如何优化滤波器性能CIFilter

时间:2018-03-12 07:56:50

标签: ios swift swift4

static func effectTransfer(image: UIImage) -> UIImage {
    let coreImage = CIImage(image: image)
    let filter = CIFilter(name: "CIPhotoEffectTransfer" )
    filter!.setDefaults()
    filter!.setValue(coreImage, forKey: kCIInputImageKey)
    let filteredImageData = filter!.value(forKey: kCIOutputImageKey) as! CIImage
    let filteredImageRef = ciContext.createCGImage(filteredImageData, from: filteredImageData.extent)

    return UIImage(cgImage: filteredImageRef!)
}

当您点击过滤器时,过滤器的应用速度非常慢,处理器会增长一到两倍到60%,我该如何优化?我做得对吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

最慢的部分是转换为CGImage。您可以直接从CIImage创建UIImage:

UIImage(ciImage: outputCI, scale: input.scale, orientation: input.imageOrientation)