我目前正在将CoreImage中的一些代码移植到GPUImage,并且在将已处理的文件保存到磁盘时遇到问题。虽然这适用于CoreImage:
guard
let blurFilter = CIFilter(name: "CIGaussianBlur"),
let imageURL = Bundle.main.url(forResource: "my-image", withExtension: "png"),
let ciImage = CIImage(contentsOf: imageURL)
else {
return
}
blurFilter.setValue(ciImage, forKey: kCIInputImageKey)
blurFilter.setValue(100, forKey: kCIInputRadiusKey)
guard
let result = blurFilter.outputImage,
let cgImage = context.createCGImage(result, from: result.extent)
else {
return
}
let destinationURL = desktopURL.appendingPathComponent("output.png")
let nsImage = NSImage(cgImage: cgImage, size: ciImage.extent.size)
以下代码移植到GPUImage:
let testImage = NSImage(named:"my-image.png")!
let blurFilter = GaussianBlur()
let filteredImage = testImage.filterWithOperation(blurFilter)
let desktopURL = FileManager.default.urls(for: .desktopDirectory, in: .userDomainMask).first!
let destinationURL = desktopURL.appendingPathComponent("output.png")
let nsImage = NSImage(nsImage: filteredImage, size: filteredImage.extent.size)
提供与最后一行有关的以下错误消息:
Value type of 'NSImage' has no member 'extent'
答案 0 :(得分:2)
filteredImage
是一个NSImage。在你的核心图像代码中,ciImage
是一个很好的CIImage。 CIImage有extent
属性,NSImage没有。
您无需在第二个代码中创建nsImage
,filteredImage
已经是NSImage。你已经完成了。