2016-10-10 72 views
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' 

回答

2

filteredImage是NSImage中。在你的Core Image代碼中,ciImage是一個CIImage。 CIImage有一個extent屬性,NSImage沒有。

沒有必要在第二個代碼中創建nsImagefilteredImage已經是NSImage。你完成了。