2017-10-19 100 views
0

我目前正在使用AVFoundation來捕捉圖像。因爲我想在Vision Framework工作流程中使用捕獲的圖像,所以在將其轉換爲UIImage時需要將其定向。我怎樣才能做到這一點? 從文檔中我發現AVCapturePhoto有一個.metadata字典來訪問這些信息,但是如果我使用相應的密鑰,我會得到nil結果。如何從AVCapturePhoto獲取元數據值?

這裏是我的捕獲例程的委託方法:

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. 

我發現在「CGImageProperties>個人形象屬性」的關鍵。打印(照片)確實告訴我一個圖像實際上已經被捕獲,返回:

AVCapturePhoto:0x1c1013940點:98386.095931 1/1設置:UID:3照片:{4032x3024 SIS:ON}

請在Swift中回答。 :)

謝謝!

回答

1

我想,你正在尋找的是:

photo.metadata["Orientation"] 

photo.metadata[String(kCGImagePropertyOrientation)] 

我希望這會幫助你。

最好! Ania

+0

事實上,這是訣竅。謝謝,阿尼亞。 –