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!)
}
When you click on a filter, the filter is applied extremely slowly, and the processor grows for a second or two to 60%, how can I optimize it? Am I doing it right?
The slowest part is converting to CGImage. You can create UIImage directly from CIImage:
UIImage(ciImage: outputCI, scale: input.scale, orientation: input.imageOrientation)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.