压缩图片质量
NSData *data = [WDCompressImage compressImageQuality:image toByte:204800];
//压缩图片质量
+ (NSData *)compressImageQuality:(UIImage *)image toByte:(NSInteger)maxLength {
CGFloat compression = 1;
NSData *data = UIImageJPEGRepresentation(image, compression);
if (data.length < maxLength) return data;
CGFloat max = 1;
CGFloat min = 0;
for (int i = 0; i < 6; ++i) {
compression = (max + min) / 2;
data = UIImageJPEGRepresentation(image, compression);
if (data.length < maxLength * 0.9) {
min = compression;
} else if (data.length > maxLength) {
max = compression;
} else {
break;
}
}
return data;
}
让明天,不后悔今天的所作所为
posted on 2017-11-20 11:23 Sinner_Yun 阅读(249) 评论(0) 编辑 收藏 举报