【问题标题】:CIPerspectiveCorrection return image as is, not stretchedCIPerspectiveCorrection 按原样返回图像,未拉伸
【发布时间】: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。

标签: ios swift crop cifilter


【解决方案1】:

如果您只想要多边形的内部原样,您可以使用 Core Graphics API 来用路径遮盖图像。 或许你可以在this question找到一些灵感。

【讨论】:

    猜你喜欢
    • 2016-01-06
    • 2015-05-06
    • 1970-01-01
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    相关资源
    最近更新 更多