How to set the resolution of a saved image from the UIImagePickerController.

Discussion in 'iOS Programming' started by BarryK88, Apr 7, 2011.

  1. BarryK88 macrumors member

    Mar 1, 2011
    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!
  2. ChOas, Apr 7, 2011
    Last edited: Apr 7, 2011

    ChOas macrumors regular

    Nov 24, 2006
    The Netherlands
    I can't check this right now, but maybe something like this ?

    - (UIImage *) thumbnailFromImage:(UIImage *)image {
        CGRect imageRect = CGRectMake(0, 0, 80, 80);
        [image drawInRect:imageRect];
        UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();
        return thumbnail;
    Something like that should work, I think ?

Share This Page