There is a lot of sample code out on the Internet for this. All this is incomplete or wrong when it comes to iPhone 4G, because iPhone 4G embeds EXIF data in its JPEG files. This data is displayed through the imageOrientation property, new in iOS 4.
The correct way to crop an area with images with EXIF rotation information is to use this alien code , but instead of using this line
UIImage *resultImage = [[[UIImage alloc] initWithCGImage:resultImageRef] autorelease];
You should call it:
UIImage *resultImage = [[[UIImage alloc] initWithCGImage:resultImageRef scale:1.0 orientation:originalImage.imageOrientation] autorelease];
The second call includes rotation information in UIImage from the original image.
Unfortunately, this call is not available in iOS 3.XX; Fortunately, it is unlikely that you will encounter images with EXIF information on these devices because the camera cannot take pictures with rotation information.
source share