How to convert CAShapeLayer coordinates to CIRectangleFeature for manual crop

*爱你&永不变心* 提交于 2019-12-12 03:43:57

问题


I am dealing with manual image crop functionality. For this am drawing CAShapeLayer with four coordinates called topLeft, topRight, bottomRight and 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.


回答1:


Set image to imageView And masking imageView with shape layer.

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

Now your imageView have crop image.

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)


来源:https://stackoverflow.com/questions/42664076/how-to-convert-cashapelayer-coordinates-to-cirectanglefeature-for-manual-crop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!