I am taking an image from the camera and want to resize it to new dimensions. When I say resize, I mean I want to keep all of the photo and just make it smaller so that it will fit into a context that I can manipulate (I understand the limit of a cgcontext is 1024). What I have is making a new image with the dimensions I want, but it is doing by cropping the photo instead of resizing it. So I am losing some of the image. What I need is to scale it down.
Any help is appreciated. I've been through several other threads and must be close, but have gotten stuck. Thanks.
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
// create a new bitmap image context to fit in maximum image dimension for cgcontext of 1024.
UIGraphicsBeginImageContext(CGSizeMake(768, 1024));
CGContextRef context = UIGraphicsGetCurrentContext();
// draw the image from the camera into the current context
[image drawInRect:CGRectMake(0, 0, 768, 1024)];
// push context to make it current (need to do this manually because we are not drawing in a UIView)
UIGraphicsPushContext(context);
// pop context Removes the current graphics context from the top of the stack, restoring the previous context, balance calls to the UIGraphicsPushContext function
UIGraphicsPopContext();
// get a UIImage from the image context
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
// clean up drawing environment
UIGraphicsEndImageContext();
// write the combined image to the photo album
UIImageWriteToSavedPhotosAlbum(outputImage, nil, nil, nil);
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}