希望這會符合您的要求
- (UIImage *)cropImage:(UIImage *)image to:(CGRect)cropRect andScaleTo:(CGSize)size {
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGImageRef subImage = CGImageCreateWithImageInRect([image CGImage], cropRect);
NSLog(@"---------");
NSLog(@"*cropRect.origin.y=%f",cropRect.origin.y);
NSLog(@"*cropRect.origin.x=%f",cropRect.origin.x);
NSLog(@"*cropRect.size.width=%f",cropRect.size.width);
NSLog(@"*cropRect.size.height=%f",cropRect.size.height);
NSLog(@"---------");
NSLog(@"*size.width=%f",size.width);
NSLog(@"*size.height=%f",size.height);
CGRect myRect = CGRectMake(0.0f, 0.0f, size.width, size.height);
CGContextScaleCTM(context, 1.0f, -1.0f);
CGContextTranslateCTM(context, 0.0f, -size.height);
CGContextDrawImage(context, myRect, subImage);
UIImage* croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRelease(subImage);
return croppedImage;
}
它不會幫助因爲相機也會旋轉圖像。在這裏看到類似的問題http://cmgresearch.blogspot.co.il/2012/07/cropping-results-from.html – Dejell 2013-01-21 18:39:57