Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BarryK88

macrumors member
Original poster
Mar 1, 2011
31
0
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:

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

macrumors regular
Nov 24, 2006
139
0
The Netherlands
[...]

Help is greatly appreciated!

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

Code:
- (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 ?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.