简体   繁体   中英

how to get focal length of camera of iPhone using AVFoundation

how can I find focal length of iPhone camera lens. I already find out lens aperture value by this:- let aperture = currentcamera?.lensAperture
print("Aperture of camera is:-",aperture!)

To do this you need to first take an image from the camera, then read its focal-length property from the Exif data returned. Sample code is given here and copied below for reference:

// 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)")
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM