您的位置:首页 > 移动开发 > IOS开发

iOS 对图片进行压缩

2017-03-11 19:41 260 查看
https://segmentfault.com/q/1010000000701850

- (UIImage *)compressImage:(UIImage *)image toMaxFileSize:(NSInteger)maxFileSize {
CGFloat compression = 0.9f;
CGFloat maxCompression = 0.1f;
NSData *imageData = UIImageJPEGRepresentation(image, compression);
while ([imageData length] > maxFileSize && compression > maxCompression) {
compression -= 0.1;
imageData = UIImageJPEGRepresentation(image, compression);
}

UIImage *compressedImage = [UIImage imageWithData:imageData];
return compressedImage;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: