UIImageView preferredImageDynamicRange not working

I am trying to display HDR Images (ProRAW) within UIImageView using preferredImageDynamicRange. This was shown in a 2023 WWDC Video

let imageView = UIImageView()
if #available(iOS 17.0, *) {
   self.imageView.preferredImageDynamicRange = UIImage.DynamicRange.high
}
self.imageView.clipsToBounds = true
self.imageView.isMultipleTouchEnabled = true
self.imageView.contentMode = .scaleAspectFit
self.photoScrollView.addSubview(self.imageView)

I pull the image from PHImageManager:

let options = PHImageRequestOptions()
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true

PHImageManager.default().requestImage(for: asset, targetSize: self.targetSize(), contentMode: .aspectFit, options: options, resultHandler: { image, info in 

     guard let image = image else {
         return
      }

     DispatchQueue.main.async {
                self.imageView.image =image
                if #available(iOS 17.0, *) {
                    self.imageView.preferredImageDynamicRange = UIImage.DynamicRange.high
                }
   }
}

Issue The image shows successfully, yet not in HDR mode (no bright specular highlights, as seen when the same image ((ProRAW) is pulled on the native camera app.

What am I missing here?

Replies

UIImageView.preferredImageDynamicRange only sets a cap on the amount of HDR that the image view will present, it cannot create HDR from nothing. If you query the image you obtained, you will likely find that it returns isHDR == false.

if I recall correctly, UIImages obtained from PHImageManager are not HDR. In order to access Gain Map HDR images from the Photo Library, you need to access the image data, and load it using UIKit's UIImageReader (or use the underlying functionality from ImageIO directly).

You you should watch the WWDC 2023 Session, Support HDR images in your app, at https://developer.apple.com/videos/play/wwdc2023/10181 for more information.