1

Using CIFIlter I want to apply same filter to multiple images I have multiple animationImages of UIImageView

        let sepiaFilter = CIFilter(name:"CIColorControls")
  let brightness =  0.8

for  image in imageView.animationImages {

                guard let ciimage = CIImage(image: image) else { return }
                if  let newimage = self.sepiaFilter(ciimage, filter: filter, intensity:brightness )
                {

                    let cgImage:CGImage = ciImageCtx!.createCGImage(newimage, from: newimage.extent)!
                    let image:UIImage = UIImage.init(cgImage: cgImage)

                    newImages.append(image)
                }



            }
        }
 func sepiaFilter(_ input: CIImage,filter: CIFilter?, intensity: Double) -> CIImage?
{
    filter?.setValue(input, forKey: kCIInputImageKey)
    filter?.setValue(intensity, forKey: kCIInputBrightnessKey)
    return filter?.outputImage
}

So let me know what is best solution to apply CIFilter to multiple images ?

Using above for loop CPU Usage increased more than 100% so it is totally wrong way.

Is it possible animations in GLKit View ? If yes let me provide deatils about it or Give best solution

**let cgImage:CGImage = ciImageCtx!.createCGImage(newimage, from: newimage.extent)!**

This line taking more CPU usage and time

Thanks.

Developer
  • 760
  • 3
  • 15
  • First, **yes** you can use `GLView` for "real-time" changes to things. I greatly recommend that and can give you code/links to help. I have a couple of apps that use a custom `CIKernel` and animated "before/after" images on 5-7 source images. (Obviously it works with a timer, but they also show "real-time" edit changes to a single source image. My animation is only for showing what each filter can do.) I suggest (a) using `GLView` or `MTKView` instead of `UIImageView` - they use the GPU - and (2) using a **single** `CIContext` and (3) only using `CGImage` when needed. –  Jan 12 '19 at 16:26
  • BONUS! (Sorry couldn't stop myself.) If you do decide to go with `GLKView`, don't - as in DO NOT - use the simulator. Use a real device instead. What takes milliseconds on a device will take *several* seconds in the simulator. (And if you are using a `MTKView`? Metal doesn't (easily) run on a simulator.) –  Jan 12 '19 at 16:28

0 Answers0