mardi 6 janvier 2015

UIImagePickerController file size is 10mb after reducing resolution by a third and cropping

I'm not sure where the problem is happening, but when I'm getting 8-10mb files even after I reduce the image quality and size of UIImagePicker's original image. Uploading to Amazon AWS shows 9mb files. Previously, they were around 1.5mb, and I don't believe I made any code changes.


I'm passing my original image to my method below;



-(void)reduceImageSize:(UIImage*)image
{
int ratio = 3;
CGSize imageSize = image.size;
CGSize newImageSize = CGSizeMake(imageSize.width / ratio, imageSize.height / ratio);
UIGraphicsBeginImageContext(newImageSize);

[image drawInRect:CGRectMake(0,0,newImageSize.width,newImageSize.height)];

UIImage* croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[NSThread detachNewThreadSelector:@selector(cropImage:) toTarget:self withObject: croppedImage];

}

-(void)cropImage:(UIImage *)oldImage {

CGSize imageSize = oldImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;

CGFloat newDimension = MIN(width, height);
CGFloat widthOffset = (width - newDimension) / 2;
CGFloat heightOffset = (height - newDimension) / 2;

UIGraphicsBeginImageContextWithOptions(CGSizeMake(newDimension, newDimension), NO, 0.);
[oldImage drawAtPoint:CGPointMake(-widthOffset, -heightOffset)
blendMode:kCGBlendModeCopy
alpha:1.];
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.cameraImage = newImage;

NSData *imgData = UIImagePNGRepresentation(self.photoData.image);
NSLog(@"Size of Image(bytes):%d",[self.cameraImage length]);
}


Any ideas on what is going on here?





Aucun commentaire:

Enregistrer un commentaire