【发布时间】:2011-06-23 05:06:36
【问题描述】:
我正在制作一个主要功能是在 tableview 中显示大图像的应用程序,其中一些可以是 1000 像素宽和 1MB+ 大小。
我发现较旧的设备 (3GS) 在处理这些问题时遇到了严重问题,并且会迅速发出内存警告。
我无法弄清楚要引入哪些图像,但我想我可以让它们在尺寸和文件大小上都更小。所以我研究了
NSData *dataForJPEGFile = UIImageJPEGRepresentation(img, 0.6)
用于压缩,但我认为这对内存警告没有帮助
调整大小如下:
UIImage *newImage;
UIImage *oldImage = [UIImage imageWithData:imageData] ;
UIGraphicsBeginImageContext(CGSizeMake(tempImage.size.width,tempImage.size.height));
[oldImage drawInRect:CGRectMake(0, 0,320.0f,heightScaled)];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
还有https://github.com/AliSoftware/UIImage-Resize
基本上,我想拍摄一张图像并重新格式化,使其更小、尺寸和文件大小在运行中,然后删除旧的。这是最好的方法吗? 缓存图像有帮助吗?喜欢https://github.com/rs/SDWebImage 吗?
【问题讨论】:
标签: iphone objective-c memory-management uiimage uiimagejpegrepresentation