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 the UIImagePickerController and you allow editing of the image. The iPhone allows the user to resize and pan the image. However, the max size of an edited image is capped at 320x320.
As an example, I took an iPhone screenshot and placed it in the photo library, which is a 480x320 png. When I use a UIImagePickerController to select that image, even if I do NOT scale or pan the image, it is cropped to 320x320 before it is returned from the UIImagePickerController. However, if I turn editing off, the image is returned the proper 480x320 size.
My theory: Very subtly, the iPhone displays 2 nonstandard translucent tool bars that overlay over the image. These toolbars leave an innocuous 320x320 "window" over the photo. It appears to me that this window effectively clips the underlying photo.
Note: The callback also returns an editing dictionary with the original image and the clipping rect, but of course the rect is also max 320x320.
Any ideas on how to allow images larger than 320x320 to be scaled and panned?
Some code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
self.myImageView.userInteractionEnabled=YES;
CGRect imageFrame = myImageView.frame;
CGPoint imageCenter = myImageView.center;
imageFrame.size = img.size;
myImageView.frame = imageFrame;
self.myImageView.image = img;
myImageView.center = imageCenter;
[self dismissModalViewControllerAnimated:YES];
[self performSelector:@selector(hideToolBars) withObject:nil afterDelay:2.0];
}
Better late than never: here's the source for the
orientationTransformForImage
functionI must be too late to answer this question, but I have got a better way to get this job done.
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 :)
As craig said, this is an issue in the dev forums and apples regular discussion board. I did, however, find a way around it. I'm using a bit of code from:
Apple Dev Forums
This includes most of what you need, and takes care of all the camera orientation issues. I've added the following which will take in the editing info and use it to get the original cropping rect with this addition:
I updated the call back method from the dev forums post to the following:
Despite your warning, it took me a precious dev hour to realize iOS 3.0+ gave us UIImagePickerControllerEditedImage which makes dealing with manually cropping to the user's pinch/zoom and dealing with orientation unnecessary.
This is in case anyone was still using UIImagePickerControllerOriginalImage and trying to figure out how best to apply cropping via UIImagePickerControllerCropRect, etc. No longer needed.
This appears to be a hindrance of the SDK, at least when setting the allowsImageEditing to TRUE on the image picker. There's a bit of discussion on this topic in the Apple forums here:
http://discussions.apple.com/message.jspa?messageID=7841993
I wrote a category on UIImage that provides a full-resolution crop. The easiest way to install is with CocoaPods, by adding UIImage-ImagePickerCrop to your podfile.