我正在制作一个主要功能是在 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一样?