Approach.1 - Use CIImage.init(data:)

let rawImageData: Data = ...

let image: CIImage? = CIImage(data: rawImageData)

<aside> 💡 This approach won't fix image orientation. To fix it needs to get the image orientation from EXIF using ImageIO.

Then, using CIImage.oriented fixes the orientation issue.

</aside>

⚠️ Caution

As this tweet says, this initializer might create a CIImage that uses a pre-rendered image in the RAW image file. which means, you might get a low-resolution image.

If the preview image is not there, I suspect CoreImage renders at the time.

https://twitter.com/olebegemann/status/1186732297409777666

Approach.2 - Use CIFilter(data: options:)

let rawImageData: Data = ...

let filter = CIFilter(imageData: rawImageData, options: [:])!
let ciImage: CIImage = filter.outputImage

<aside> ⚠️ This approach won't work on iOS Simulator. CIFilter.outputImage returns nil.

</aside>

This approach renders bitmap image from RAW data with options. Actually that CIFilter is CIRawFilter implicitly.

To convert to UIImage: