在我的 iPad 应用程序中,我允许用户拍摄多张照片,然后压缩所有图像并将其上传到服务器。我面临的问题是由于大尺寸图像,zip 文件的大小正在增加,并且在上传时失败。单击图像后如何立即保存低质量图像。
2 回答
            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 倍,直到它减小到小于最大图像大小的大小
于 2012-06-14T06:19:43.590   回答
    
    
            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;
  }
您可以将所有选取的图像存储在数组中。现在在创建 zip 调整图像大小之前:
  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
  }
于 2012-06-14T06:15:06.387   回答