gpt4 book ai didi

ios - 不确定如何使用 CICrop 裁剪图像

转载 作者:搜寻专家 更新时间:2023-10-31 22:07:38 25 4
gpt4 key购买 nike

我正在尝试使用 CICrop 裁剪图像,但是当我尝试裁剪时,它崩溃并显示以下错误消息:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key CIAttributeTypeRectangle.' *** First throw call stack: (0x1847fc2d8 0x1964c80e4 0x1847fbf5c 0x184e34a4c 0x185635480 0x10005e554 0x10005eb7c 0x1892a9398 0x189292474 0x1892a8d34 0x1892a89c0 0x1892a1efc 0x189275120 0x1895162b8 0x189273634 0x1847b4240 0x1847b34e4 0x1847b1594 0x1846dd2d4 0x18e1336fc 0x1892daf40 0x10006481c 0x196b72a08) libc++abi.dylib: terminating with uncaught exception of type NSException

这是我的代码:

@IBAction func CropButton(sender: UIButton)
{
let CropBoxHeight = CGFloat(200)
let CropBoxWidth = CGFloat(200)
let Rectangle = CIVector(x: view.center.x, y: view.center.y, z: 200, w: 200)
let filter = CIFilter(name: "CICrop")
let inputImage = CIImage(image: originalImage)

let ciContext = CIContext(options: nil)

filter.setDefaults()
filter.setValue(inputImage, forKey: kCIInputImageKey)
filter.setValue(Rectangle, forKey: kCIAttributeTypeRectangle)

let originalOrientation: UIImageOrientation = imageView.image!.imageOrientation
let originalScale = imageView.image!.scale

let cgImage = ciContext.createCGImage(filter.outputImage, fromRect: inputImage.extent())

imageView.image = UIImage(CGImage: cgImage, scale: originalScale, orientation: originalOrientation)!
}

它在这一行崩溃: filter.setValue(Rectangle, forKey: kCIAttributeTypeRectangle)

最佳答案

看来你需要用

filter.setValue(Rectangle, forKey: "inputRectangle")

代替

filter.setValue(Rectangle, forKey: kCIAttributeTypeRectangle)

这可以在 official documentation 中找到.但是,我没有设法找到该键的任何内置常量。

关于ios - 不确定如何使用 CICrop 裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31946075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com