Created
May 4, 2014 06:10
-
-
Save nonstriater/57f7ba74aa383b9cc216 to your computer and use it in GitHub Desktop.
图片强制解压缩优化技巧
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
图片优化技巧 | |
- (void)decompressImage:(UIImage *)image | |
{ | |
UIGraphicsBeginImageContext(CGSizeMake(1, 1)); | |
[image drawAtPoint:CGPointZero]; | |
UIGraphicsEndImageContext(); | |
} | |
This causes the image to decompress | |
同样的,这个函数也完成了image data的解压 | |
- (UIImage *)compressImage:(UIImage *)image | |
{ | |
CGSize size = {36.0f, 36.0f}; | |
UIGraphicsBeginImageContextWithOptions(size, NO, [[UIScreen mainScreen] scale]); | |
[image drawInRect:CGRectMake(0, 0, size.width, size.height)]; | |
image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} | |
我猜测,UIImage对象初始化,只是持有了data数据,真正要显示的时候才开始解压数据--》CGContext纹理--》复制到显存---》GPU display | |
所以这里提前调用 draw 方法解压数据,在主线程中只 display image | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment