meaning-matters
meaning-matters

Reputation: 22946

Fastest way to render CIImage to JPEG?

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?

Upvotes: 0

Views: 897

Answers (1)

Frank Rupprecht
Frank Rupprecht

Reputation: 10398

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)

Upvotes: 1

Related Questions