Update:
With iPhone OS 3.0+, the whole UIImagePickerController API has changed. This question and answer should be considered 2.2. legacy code.
When using
I must be too late to answer this question, but I have got a better way to get this job done.
static inline double radians (double degrees) {return degrees * M_PI/180;}
+(UIImage*)editedImageFromMediaWithInfo:(NSDictionary*)info{
if(![info objectForKey:UIImagePickerControllerCropRect])return nil;
if(![info objectForKey:UIImagePickerControllerOriginalImage])return nil;
UIImage *originalImage=[info objectForKey:UIImagePickerControllerOriginalImage];
CGRect rect=[[info objectForKey:UIImagePickerControllerCropRect] CGRectValue];
CGImageRef imageRef = CGImageCreateWithImageInRect([originalImage CGImage], rect);
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);
CGContextRef bitmap = CGBitmapContextCreate(NULL, rect.size.width, rect.size.height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
if (originalImage.imageOrientation == UIImageOrientationLeft) {
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -rect.size.height);
} else if (originalImage.imageOrientation == UIImageOrientationRight) {
CGContextRotateCTM (bitmap, radians(-90));
CGContextTranslateCTM (bitmap, -rect.size.width, 0);
} else if (originalImage.imageOrientation == UIImageOrientationUp) {
// NOTHING
} else if (originalImage.imageOrientation == UIImageOrientationDown) {
CGContextTranslateCTM (bitmap, rect.size.width, rect.size.height);
CGContextRotateCTM (bitmap, radians(-180.));
}
CGContextDrawImage(bitmap, CGRectMake(0, 0, rect.size.width, rect.size.height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *resultImage=[UIImage imageWithCGImage:ref];
CGImageRelease(imageRef);
CGContextRelease(bitmap);
CGImageRelease(ref);
return resultImage;
}
It only crops the original image with the relative CropRect, although this method dosen't scale the image, but it is short and sweet for me. Just for reference :)