gpt4 book ai didi

ios - 设置 CIFiltered UIImage 时 UIImageVIew 崩溃

转载 作者:行者123 更新时间:2023-11-28 11:35:48 25 4
gpt4 key购买 nike

我正在尝试“CIFiltering”一些图像。但是 UIImageView 在放置过滤后的 uiimage 时崩溃。我从未见过这种情况,也不知道下一步该怎么做。请帮助或教一些技巧。谢谢。

https://developer.apple.com/documentation/coreimage/simulating_scratchy_analog_film

enter image description here这就是发生的事情。

最佳答案

请在函数中做如下修改:

在函数的开头添加:

public func filter(_image) {
let aUIImage = _image

guard let aCGImage = aUIImage.cgImage else { return }
let aCIImage = CIImage(cgImage: aCGImage)
let context = CIContext(options: nil)

并将这一行 let image = UIImage(ciImage: speckledImage) 替换为:

let imageRef = context.createCGImage(speckledImage, from: aCIImage.extent)
let image = UIImage(cgImage: imageRef!)

原因:

You are creating an CIImage and trying to attach it to UIImageView which is not possible. According to apple docs : Although a CIImage object has image data associated with it, it is not an image.

有关更多信息,请参阅此链接:https://developer.apple.com/documentation/coreimage/ciimage

关于ios - 设置 CIFiltered UIImage 时 UIImageVIew 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55452731/

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