I want to use the native filters for my app, the function works but I want to avoid methods that will be removed from the documentation. I search over the whole internet and no solution.
I search over the whole internet and i haven't found any solution at my problem.
public func applyFilterTo(image: UIImage, filterEffect: Filter) -> UIImage? {
guard let cgImage = image.cgImage,
let openGLContext = EAGLContext(api: .openGLES3) else {
return nil
}
let context = CIContext(eaglContext: openGLContext)
let ciImage = CIImage(cgImage: cgImage)
let filter = CIFilter(name: filterEffect.filterName)
filter?.setValue(ciImage, forKey: kCIInputImageKey)
if let filterEffectValue = filterEffect.filterEffectValue, let filterEffectValueName = filterEffect.filterEffectValueName {
filter?.setValue(filterEffectValue, forKey: filterEffectValueName)
}
var filteredImage: UIImage?
if let output = filter?.value(forKey: kCIOutputImageKey) as? CIImage,
let cgiImageResult = context.createCGImage(output, from: output.extent) {
filteredImage = UIImage(cgImage: cgiImageResult)
}
return filteredImage
}
The result is good but my concern is voiding warnings in my app. Thanks
EAGLContext is part of OpenGL, which is deprecated. You should switch to Metal at this stage.
来源:https://stackoverflow.com/questions/55582603/what-can-be-the-solution-of-a-deprecated-of-eaglcontext