How do I get data from a UIImage?

Asked on 09/01/2024

1 search

To get data from a UIImage, you can use the following approach:

  1. Convert UIImage to CIImage: You can initialize a CIImage with a UIImage to work with Core Image filters and other image processing tasks.

  2. Access Image Data:

    • If you need to access the raw pixel data, you can convert the UIImage to a CGImage and then use CGDataProvider to get the pixel data.
    • Alternatively, you can use UIImagePNGRepresentation or UIImageJPEGRepresentation to get the image data in PNG or JPEG format, respectively.
  3. Working with HDR Images:

    • If you are dealing with HDR images, you can use the expand HDR option when initializing a CIImage to ensure you are working with the HDR representation of the image. This is particularly useful for adaptive HDR files, as mentioned in the session Use HDR for dynamic image experiences in your app.

For more detailed information on handling HDR images, you can refer to the session "Use HDR for dynamic image experiences in your app" from WWDC 2024.