This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation UIImage (Decompressed) | |
+ (UIImage *)decompressedImageWithContentsOfFile:(NSString *)path | |
{ | |
NSDictionary *dict = @{(id)kCGImageSourceShouldCache : @(YES)}; | |
NSData * data = [NSData dataWithContentsOfFile:path]; | |
if (data == nil) { | |
return nil; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
func decompressed() -> UIImage? { | |
guard let image = self.cgImage else { return nil } | |
let colorSpace = CGColorSpaceCreateDeviceRGB() | |
guard let context = CGContext(data: nil, width: image.width, height: image.height, bitsPerComponent: 8, bytesPerRow: image.width * 4, space: colorSpace, bitmapInfo: UInt32(CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Little.rawValue)) else { return nil } | |
let rect = CGRect(origin: .zero, size: CGSize(width: image.width, height: image.height)) | |
context.draw(image, in: rect) | |
let decompressedImage = UIImage(cgImage: image, scale: UIScreen.main.scale, orientation: .up) |