Shantanu
Shantanu

Reputation: 3136

iPad+Set imagepickers quality to low

In my iPad App I allow the user to take multiple photos and then zip all the images and upload it to server. The problem i am facing is due to large size images,the size of the zip file is increasing and it fails while uploading. How can i save low quality images immediately after image is clicked.

Upvotes: 0

Views: 99

Answers (2)

raja
raja

Reputation: 194

Image is captured in png format.Convert it to JPG format.This will help reduce size of image to some extent.

or else compress image by some factor

here is the code

//code

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;

here set MAX_SIZE_IMage to some value and then compress image by factor of 0.1 till it reduces to size less than max image size

Upvotes: 1

Paresh Navadiya
Paresh Navadiya

Reputation: 38239

FUnction to resize image:

  -(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;
  }

You can store all images picked in array. Now before creating zip resize image to your size:

  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
  }

Upvotes: 0

Related Questions