使用UIImagePNGRepresentation和UIImageJPEGRepresentation来压缩图片, 文件属性格式并不会压缩,压缩的是图片内容(像素)压缩后的图片显示到屏幕上还是会很占内存,使用 上下文生成bitmap图像可以进行压缩 方法如下
- (UIImage*)scaleImage:(UIImage*)image size:(CGSize)imageSize{
UIGraphicsBeginImageContext(imageSize);
[image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}