[英]How to get the correctly region to crop an UIImage?
我的目标C应用程序中有一个UIImageView
。 在此UIImageView
我加载图片,然后从相机拍摄。 我应用一个区域来裁剪UIImage
。 该区域是CAShapeLayer
的矩形。 但是我的问题是,当我将框架包含在矩形中时,这与矩形的位置不同……我得到了一个错误的区域,然后进行了裁剪。
我使用以下代码:
CAShapeLayer *_outline = [CAShapeLayer new];
UIImageView *vistaImagen;
...
UIGraphicsBeginImageContextWithOptions(_vistaImagen.frame.size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context, _boundingBox.accessibilityPath.CGPath);
CGContextClip(context);
[_vistaImagen.layer renderInContext:context];
UIImage *iii = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
如果我添加了要裁剪的图层框架,可能是什么问题: _boundingBox.accessibilityPath.CGPath
?
谢谢!!
好吧,花了几个小时后,我发现了问题。 我正在使用错误的缩放比例创建UIGraphicsBeginImageContextWithOptions ...我需要将比例缩放为1,因为我正在以真实比例在UIImage中获取图像,但是缩放比例已初始化为0。
UIImageView *vistaImagen;
UIGraphicsBeginImageContextWithOptions(_vistaImagen.frame.size, NO, 1.0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.