Home > Software design >  Fastest way to render CIImage to JPEG?
Fastest way to render CIImage to JPEG?

Time:11-19

I have a CIFilter pipeline.

It currently outputs UIImage using:

private func renderImage(ciImage: CIImage) -> UIImage?
{
    let cgImage = Filter.context.createCGImage(ciImage, from: ciImage.extent)

    return cgImage.map(UIImage.init)
}

This UIImage is later converted to JPEG and stored.

There's now a demand to filter images in bulk and skip the UIImage format. This needs to be done as fast as possible.

Here are a few ways to do this.

Which way is the fastest?

CodePudding user response:

You can do that with the CIContext as well:

let colorSpace = CGColorSpace(name: CGColorSpace.sRGB)!
// if you need the JPEG data
let data = Filter.context.jpegRepresentation(of: ciImage, colorSpace: colorSpace)
// or if you want to write to file directly
try Filter.context.writeJPEGRepresentation(of: ciImage, to: url, colorSpace: colorSpace)
  • Related