In my app, user is allowed to take a photo from a device or upload it from the library to set it as his profile pic. Now when user is done, I need to upload that image to server. Usually the image taken from device is of size 5-6MB. I need it to compress to 25KB before uploading to server. So I am using following method to that
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
profilePicImageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData* pngData = UIImagePNGRepresentation(profilePicImageView.image);
NSLog(@"image size of png is %d", [pngData length]);
NSData *imageData = UIImageJPEGRepresentation(profilePicImageView.image, 0.00001);
NSLog(@"image size is %d", [imageData length]);
}
Problem with this method is, no matter how small I set the scaling parameter, compressed file size does not drop below ~230KB, which is nearly 10 times higher than what I need.
What is wrong with the above method? Can’t I compress image to 25KB?
Any help, suggestion will be greatly appreciated.
I think Below code may help you to do what you want, please remove some of my code before using in your app.
This will surely solve your issues with image make this common method to use in multiple views…