Saurav_Sharma
Saurav_Sharma

Reputation: 140

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!)

Upvotes: 0

Views: 1266

Answers (1)

Mohammad Assad Arshad
Mohammad Assad Arshad

Reputation: 1784

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

Upvotes: 1

Related Questions