1

我想保持 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);
   }

但是上传图片的所有方式都是630297没有改变,怎么办

编辑:我修改

NSData *uploadpic = UIImageJPEGRepresentation(tempImg, 0.5);

作为

UIImageJPEGRepresentation(tempImg, compressionQuality)

一切正常。

但我有一个问题:为什么设置一个固定值 0.5 ,它没有改变。每次改变0.5为什么不正确?

4

0 回答 0