【问题标题】:Swift, blurred images in UITableViewCell does not run smoothUITableViewCell 中快速、模糊的图像运行不流畅
【发布时间】:2021-03-16 12:18:45
【问题描述】:

我想要做的是显示来自网络的模糊图像列表。这适用于我的自定义 UITableViewCell 中的此代码

func blurImage(image:UIImage, imageView: UIImageView) {

    DispatchQueue.global(qos: .background).async {
    
        let inputImage = CIImage(image: image)
        let originalOrientation = image.imageOrientation
        let originalScale = image.scale

          let filter = CIFilter(name: "CIGaussianBlur")
          filter?.setValue(inputImage, forKey: kCIInputImageKey)
          filter?.setValue(15.0, forKey: kCIInputRadiusKey)
          let outputImage = filter?.outputImage

          var cgImage:CGImage?

          if let outputImage = outputImage{
            cgImage = self.context.createCGImage(outputImage, from: (inputImage?.extent)!)
          }
        
        DispatchQueue.main.async {
                if let cgImageA = cgImage{
                    imageView.image = UIImage(cgImage: cgImageA, scale: originalScale, orientation: originalOrientation)
                }
            }
        }
    }

问题是模糊计算需要一些时间,而且所有认为它在 BG 线程上的滚动并没有那么快和流畅,好像我根本没有模糊效果。

有没有办法让它运行更流畅或显示占位符图像,直到准备好再次绘制模糊图像以实现平滑滚动?

【问题讨论】:

    标签: swift uitableview gaussianblur


    【解决方案1】:

    第 1 步)不要将 qos: .background 用于用户启动的任务。文档说:后台任务在所有任务中的优先级最低。将此类分配给您的应用在后台运行时用于执行工作的任务或调度队列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 2013-02-05
      • 1970-01-01
      • 2011-01-05
      • 2016-06-09
      • 1970-01-01
      相关资源
      最近更新 更多