【发布时间】:2019-11-28 20:27:28
【问题描述】:
我正在使用 CIFilter 的 CIPerspectiveCorrection 裁剪图像,但我想要裁剪的部分并不总是完美的矩形,因此裁剪后的图像返回失真。
let filter: CIFilter = CIFilter(name: "CIPerspectiveCorrection")!
filter.setValue(CIImage(cgImage: inputImage.cgImage!), forKey: "inputImage")
filter.setValue(CIVector(cgPoint: topLeft), forKey: "inputTopLeft")
filter.setValue(CIVector(cgPoint: topRight), forKey: "inputTopRight")
filter.setValue(CIVector(cgPoint: bottomLeft), forKey: "inputBottomLeft")
filter.setValue(CIVector(cgPoint: bottomRight), forKey: "inputBottomRight")
let cutImageRef = CIContext(options: nil).createCGImage(filter.outputImage!, from: filter.outputImage!.extent)!
// Return image to UIImage
let croppedImage: UIImage = UIImage(cgImage: cutImageRef)
return croppedImage
如何在不拉伸以填充矩形的情况下返回 2d 平面上的图像?
【问题讨论】:
-
您只想使用 CICrop 过滤器进行直接裁剪吗?
-
我只想要里面的内容,就像我在四边形中看到的那样,不一定是矩形。
-
"如何在不拉伸填充矩形的情况下将图像原样返回 2d 平面?"这不是 CIPerspectiveCorrection 的用途。
-
我没用过,不过试试用CICrop吧。
-
好像CICrop只接受一个矩形作为key。