PDA

View Full Version : How to set the resolution of a saved image from the UIImagePickerController.




BarryK88
Apr 7, 2011, 04:40 AM
I'm using an UIImagePickerController to set a picture from my cameraroll to a UIImageView. However the image is getting scaled automaticly inside this UIImageView because I mentioned 'scale to fit' inside the IB. I'd like to save my chosen image with a resolution of 80x80 pixels so that I won't have to scale. (My App is getting realy slow because of this scaling issue.)

Here's a snippit from my code:

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
photoView.image = image;


NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/foto1.png",docDir];
NSData *data = [NSData dataWithData:UIImagePNGRepresentation(image)];

[data writeToFile:pngFilePath atomically:YES];
}

Help is greatly appreciated!



ChOas
Apr 7, 2011, 06:13 AM
[...]

Help is greatly appreciated!

I can't check this right now, but maybe something like this ?


- (UIImage *) thumbnailFromImage:(UIImage *)image {

CGRect imageRect = CGRectMake(0, 0, 80, 80);

UIGraphicsBeginImageContext(imageRect.size);

[image drawInRect:imageRect];

UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return thumbnail;
}



Something like that should work, I think ?