如何使用 AVFoundation 获取 iPhone 相机的焦距

how to get focal length of camera of iPhone using AVFoundation

如何找到 iPhone 相机镜头的焦距。 我已经通过这个找出镜头光圈值:- let aperture = currentcamera?.lensAperture
print("Aperture of camera is:-",aperture!)

为此,您需要先从相机拍摄图像,然后从返回的 Exif 数据中读取其焦距 属性。给出示例代码,复制如下供参考:

// delegate method for the image picker
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary
    let exifdata = metadata!["{Exif}"] as! NSDictionary

    // focal length
    let focalLength = exifdata["FocalLength"] as! Double

    print("Focal length \(focalLength)")
}