[英]crop a rotated 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上裁剪。
您正在使用的“解决方案”尽管已被接受,但仍带有OP注释“但不起作用”。
该解决方案仅声称要处理问题的轮换部分,而不是庄稼。 它正在做它声称要做的事情,但仅此而已。
这是执行裁剪的CG函数:
CGImageRef CGImageCreateWithImageInRect (
CGImageRef image,
CGRect rect
);
输入图像和要裁剪的区域的矩形。
有关示例用法,请参见此处的答案:
裁剪UIImage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.