【发布时间】:2016-02-20 10:18:24
【问题描述】:
我正在使用 swift 开发图像过滤器视图。用户可以通过相机捕获图像或从图像库中选择一张图像。然后我的应用程序将根据该图像创建 8 个过滤器图像并将它们显示给用户。用户可以选择其中一个过滤器图像以显示在更大的图像视图上。下面是生成过滤图像的代码。如果图像很大,我的应用程序将创建一些大型过滤器图像,这会导致内存使用量增加。有没有办法减小滤镜图像的大小?
func outputImage(filter: CIFilter, originalImage: UIImage) -> UIImage{
let inputImage = CIImage(image: originalImage)
filter.setValue(inputImage, forKey: kCIInputImageKey)
let cgImage = context!.createCGImage(filter.outputImage!, fromRect: (filter.outputImage?.extent)!)
return UIImage(CGImage: cgImage, scale: 1, orientation: originalImage.imageOrientation)
}
【问题讨论】: