CIImage说“无法使用金属上下文渲染图像(使用输入金属纹理)。”

时间:2018-03-20 02:33:26

标签: swift metal cimage

我试图通过向我的macOS playground中的MTLTexture对象添加扩展函数来将MTLTexture转换为CGImage。

当前函数如下所示:

extension MTLTexture {
    func toImage() -> CGImage? {
        let context = CIContext()
        let texture = self
        let cImg = CIImage(mtlTexture: texture, options: nil)!
        let cgImg = context.createCGImage(cImg, from: cImg.extent)!
        return cgImg
    }
}

然而,应该初始化cImg的行导致concole打印Cannot render image (with an input Metal texture) using a metal context.并返回nil。

为什么会发生这种情况,我该如何解决?

0 个答案:

没有答案