0

我有这里描述的确切问题:

裁剪一个旋转的 UIImage

我需要裁剪旋转的 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 上裁剪。

4

1 回答 1

0

您正在使用一个“解决方案”,虽然被接受,但也带有 OP 评论“但它不起作用”。

该解决方案仅声称处理问题的轮作部分,而不是作物。它正在做它声称要做的事情,但仅此而已。

这是一个执行裁剪的 CG 函数:

CGImageRef CGImageCreateWithImageInRect (
   CGImageRef image,
   CGRect rect
);

输入您的图像和要裁剪到的区域的矩形。

请参阅此处的答案以获取示例用法:
裁剪 UIImage

于 2013-02-03T13:07:07.623 回答