Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CIPerspectiveCorrection按原样返回图像,未拉伸_Ios_Swift_Crop_Cifilter - Fatal编程技术网

Ios CIPerspectiveCorrection按原样返回图像,未拉伸

Ios CIPerspectiveCorrection按原样返回图像,未拉伸,ios,swift,crop,cifilter,Ios,Swift,Crop,Cifilter,我正在使用CIFilter的CIPerspectiveCorrection来裁剪图像,但是我想要裁剪的部分并不总是一个完美的矩形,因此裁剪后的图像会返回扭曲 如何在不拉伸以填充矩形的情况下返回二维平面上的图像?如果只需要多边形的内部,可以使用Core Graphics API使用路径遮罩图像。 也许你可以从中找到一些灵感。你只想使用CICrop过滤器进行直接裁剪吗?我只想看到四边形中的内容,不一定是矩形。“如何返回二维平面上的图像,而不拉伸填充矩形?”这不是CIPerspectiveCorre

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


如何在不拉伸以填充矩形的情况下返回二维平面上的图像?

如果只需要多边形的内部,可以使用Core Graphics API使用路径遮罩图像。
也许你可以从中找到一些灵感。

你只想使用CICrop过滤器进行直接裁剪吗?我只想看到四边形中的内容,不一定是矩形。“如何返回二维平面上的图像,而不拉伸填充矩形?”这不是CIPerspectiveCorrection的用途。我从未使用过它,但尝试使用CICrop来代替。似乎CICrop只接受矩形作为键。
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