ios - 对于键 'CIAttributeTypeRectangle.',此类不符合键值编码

标签 ios swift filter

我正在学习如何编程,并且正在尝试使用相机。我一直在尝试将 CICrop 过滤器应用于图像,但每次都会崩溃。这是代码:

let Rectangle = CIVector(x: view.center.x, y: view.center.y, z: view.bounds.height, w: view.bounds.width)

let filter = CIFilter(name: "CICrop")
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)

有人可以帮我解决发生的事情吗?另外,请在答案中提供代码,因为正如我之前所说,我仍在努力学习。谢谢!

最佳答案

“不符合键值编码”错误通常是因为您的 socket 不再连接到 View Controller 。右键单击 Storyboard中的 imageView,查看是否有任何过时的引用导出(即从代码中删除但未从 Storyboard对象中删除)。

关于ios - 对于键 'CIAttributeTypeRectangle.',此类不符合键值编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31905778/

相关文章:

ios - 禁用手势下拉表单/页面表模式呈现

iphone - iOS+ Parse.com : kPFCachePolicyCacheThenNetwork, 两次获取数据

ios - 当 JSON 输入表示 Codable 类型的多个子类时使用 Codable

swift - 点击更改 Collection View 数据源

swift - 如何使结构符合具有属性的协议(protocol)符合 swift 4 中的另一个协议(protocol)?

python - 为什么 Python 的 filter(predicate, set) 不返回一个集合?

ios - 使用反余弦的线之间的绝对角度

ios - 直接编辑 UITextField.text 属性 UITextFieldDelegate 不会触发

python - 分割大列表的最快方法

jquery - 获取 jQuery .filter() 结果的相反/相反结果