Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I obtain a metadata value from AVCapturePhoto?

I am currently working on capturing an image using AVFoundation. As I want to use the captured image on a Vision Framework workflow, I need its orientation when converting it to a UIImage. How can I achieve that? From the documentation I found that AVCapturePhoto has a .metadata dictionary to access that information, but if I use the corresponding key I get nil as a result.

Here's my delegate method for the capture routine:

    func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
    // capture image finished
    print("Image captured.")
    print(photo)
    print(photo.metadata["kCGImagePropertyOrientation"]) // CGImageProperties for metadata keys for value retrieval.

I found the key under "CGImageProperties>Individual Image Properties". The print(photo) does show me an image has actually been captured, returning:

AVCapturePhoto: 0x1c1013940 pts:98386.095931 1/1 settings:uid:3 photo:{4032x3024 SIS:ON}

Please answer in Swift. :)

Thanks!

like image 497
Andre Guerra Avatar asked Oct 17 '25 18:10

Andre Guerra


1 Answers

I think, what you are looking for is:

photo.metadata["Orientation"]

or

photo.metadata[String(kCGImagePropertyOrientation)]

I hope it will help you.

Best! Ania

like image 50
A Widera Avatar answered Oct 20 '25 08:10

A Widera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!