简体   繁体   English

如何将CAShapeLayer坐标转换为CIRectangleFeature进行手动裁剪

[英]How to convert CAShapeLayer coordinates to CIRectangleFeature for manual crop

I am dealing with manual image crop functionality. 我正在处理手动图像裁剪功能。 For this am drawing CAShapeLayer with four coordinates called topLeft, topRight, bottomRight and bottomLeft. 为此,绘制CAShapeLayer的四个坐标分别为topLeft,topRight,bottomRight和bottomLeft。 User can pan the points and select the crop area. 用户可以平移点并选择裁剪区域。 I am stuck at converting these points to Core image coordinates and further cropping with CIPerspectiveTransform. 我一直坚持将这些点转换为Core图像坐标,并使用CIPerspectiveTransform进一步裁剪。

Set image to imageView And masking imageView with shape layer. 将图像设置为imageView并使用形状图层蒙版imageView。

self.imageView = img
imageView.layer.mask = shapeLayer // set here your shape layer

Now your imageView have crop image. 现在,您的imageView具有裁剪图像。

Get image from current context as follow 从当前上下文获取图像,如下所示

UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, 0);
imageView.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// check cropping image
let resultImageView = UIImageView(frame: self.view.frame)
resultImageView.image = image
self.view.addSubview(resultImageView)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM