【问题标题】:How to reduce filter image size in iOS如何在 iOS 中减小滤镜图像大小
【发布时间】: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)
}

【问题讨论】:

    标签: ios swift image memory


    【解决方案1】:

    要减小图像大小,您可以使用:

    newImage = UIImageJPEGRepresentation(image: UIImage, compressionQuality: CGfloat)
    

    【讨论】:

    • 我已经尝试过这种方法,但它仍然不能解决我的问题。可能与图片大小无关。它可能是由其他原因引起的。
    • 查看这篇文章,让我知道:stackoverflow.com/questions/29137488/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 2019-07-11
    • 2014-10-30
    相关资源
    最近更新 更多