ios - CIPerspectiveCorrection 按原样返回图像,未拉伸(stretch)

标签 ios swift crop cifilter

我正在使用 CIFilter 的 CIPerspectiveCorrection 来裁剪图像,但我想要裁剪的部分并不总是一个完美的矩形,因此裁剪后的图像返回失真。

enter image description here

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 平面上按原样返回图像而不拉伸(stretch)以填充矩形?

最佳答案

如果你只想要多边形的内部,你可以使用 Core Graphics APIs 来用路径屏蔽图像。
也许你可以在 this question 中找到一些灵感.

关于ios - CIPerspectiveCorrection 按原样返回图像,未拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57119302/

相关文章:

ios - 在 ImageView 上加载图像时内存增加?

MeteorJS 的 iOS 9 Beta 2 网络问题

ios - 如何将iTunesAccount帐户添加或链接到其他人的Apple Developer帐户?

ios - AFNetworking POST 写入服务器并返回失败错误(Cocoa 错误 3840)

ios - 当该页面出现时,如何在 UISearchController 中自动启用搜索栏?

ios - {"msg":"Fence: onClientEventRegionState, invalid state", "regionState":"0"} 在 ios 中

c# - 如何在不更改 C#.Net 中的分辨率的情况下裁剪图像?

ios - 允许用户在 UIImage 上绘制矩形,以裁剪图像

ios - 将我自己的应用程序从设备传输到 xcode

html - 无论页面大小如何,将标题图像居中