1
我目前正在將CoreImage中的代碼部分移植到GPUImage,並且在將處理後的文件保存到磁盤時遇到問題。GPUImage與MacOS - 如何將處理後的文件保存到磁盤
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:雖然這與CoreImage工作
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'