Reputation: 1177
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!
Upvotes: 4
Views: 1699
Reputation: 176
I think, what you are looking for is:
photo.metadata["Orientation"]
or
photo.metadata[String(kCGImagePropertyOrientation)]
I hope it will help you.
Best! Ania
Upvotes: 5