方式一:
NSURL *imageURL = [NSURL fileURLWithPath:path];
//使用kCGImageSourceShouldCache来创建图片,强制图片立刻解压
NSDictionary *options = @{(__bridge id)kCGImageSourceShouldCache: @YES};
CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)imageURL, NULL);
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(source, 0,(__bridge CFDictionaryRef)options);
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CFRelease(source);
方式二:
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
//redraw image using device context 图片渲染到CGContext也会解压图片
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, YES, 0);
[image drawInRect:imageView.bounds];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();