我正在学习如何编程,并且正在尝试使用相机。我一直在尝试将 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/