【发布时间】:2013-02-03 11:37:32
【问题描述】:
我遇到了这里描述的确切问题:
我需要裁剪旋转的 UIImage,但是,当我尝试解决方案时,它不会裁剪图像
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:videoPreviewView.frame];
NSLog(@"frame width: %f height:%f x:%f y:%f",videoPreviewView.frame.size.width, videoPreviewView.frame.size.height,videoPreviewView.frame.origin.x,videoPreviewView.frame.origin.y);
rotatedViewBox.transform = CGAffineTransformMakeRotation(90 * M_PI / 180);
CGSize rotatedSize = rotatedViewBox.frame.size;
UIGraphicsBeginImageContext(rotatedSize);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(bitmap, rotatedSize.width / 2.0f, rotatedSize.height / 2.0f);
CGContextRotateCTM(bitmap, 90 * M_PI / 180);
CGContextScaleCTM(bitmap, 1.0f, -1.0f);
CGContextDrawImage(bitmap, CGRectMake(-videoPreviewView.frame.size.width / 2.0f,
-videoPreviewView.frame.size.height / 2.0f,
videoPreviewView.frame.size.width,
videoPreviewView.frame.size.height),
image.CGImage);
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
日志是: 框架宽度:310 高度:310 x:0 y: 69
虽然旋转有效,但新图像未在旧图像的 0,69,310,310 处裁剪。
【问题讨论】:
-
“不起作用”什么也没告诉我们。请提供更多详细信息。
-
我更新了问题 - 它根本不裁剪图像。只有旋转有效
标签: iphone objective-c cocoa-touch uiview uiimage