我想保持UIImage的宽度和高度不变,但更改我使用的UIimage文件大小:
NSData *uploadpic = UIImageJPEGRepresentation(photoData, 0.5);
int compressionQuality=0.5;
while (uploadpic.length>500000) {
compressionQuality=compressionQuality+0.1;
if(compressionQuality>=1){
compressionQuality=1;
}
UIImage *tempImg=[UIImage imageWithData:uploadpic];
uploadpic = UIImageJPEGRepresentation(tempImg, 0.5);
NSLog(@"uploadpic = %d", uploadpic.length);
}
但是uploadpic的所有方式都是630297没有改变,怎么办
编辑:我修改了
NSData *uploadpic = UIImageJPEGRepresentation(tempImg, 0.5);
as
UIImageJPEGRepresentation(tempImg, compressionQuality)
一切都好。
但我有一个问题:为什么设置固定值0.5,它不会改变。每次改变0.5为什么不正确?