iPad +将图像采集器的质量设置为低

时间:2012-06-14 05:29:50

标签: objective-c ios ipad

在我的iPad应用程序中,我允许用户拍摄多张照片,然后将所有图像压缩并上传到服务器。我面临的问题是由于大尺寸图像,zip文件的大小正在增加,并且在上传时失败。如何在点击图像后立即保存低质量图像。

2 个答案:

答案 0 :(得分:1)

以png格式捕获图像。将其转换为JPG格式。这将有助于在一定程度上减小图像的大小。

或者按某种因素压缩图像

这是代码

//代码

if(imagesize>[MAX_SIZE_IMAGE intValue]){

   while (imagesize>[MAX_SIZE_IMAGE intValue]){

        NSData *data=UIImageJPEGRepresentation(Image, 0.1f);

        imagesize=[data length];
    }
}

jpgImage =[UIImage imageWithData:data];

return jpgImage;

这里将MAX_SIZE_IMage设置为某个值,然后按因子0.1压缩图像,直到它缩小到小于最大图像大小

答案 1 :(得分:0)

调整图像大小的功能:

  -(UIImage *)resizeImage:(UIImage *)image width:(float)imgwidth height:(float)imgheight
  {
   CGSize imgSize; 
   imgSize.width= imgwidth;
   imgSize.height= imgheight;
   UIGraphicsBeginImageContext(imgSize);
   [image drawInRect:CGRectMake(0,0,imgSize.width,imgSize.height)];
   UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
   return newImage;
  }

您可以存储以阵列方式挑选的所有图像。现在,在创建拉链调整大小图像到您的尺寸之前:

  for(int i = 0; [array count]; i++)
  {
    // call resize function here
    //Again store all resized image in another array Now u have all images in low quality for zip
  }