Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Swift: Get clicked image by camera

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 544
    Comment on it

    Hi All,

    Sometime we have to take a picture using camera and use that image , we have to follow these simple steps.


    1) Ask permission to access camera and microphone. Add these key and value in your project plist:-

    <string>This app does not require access to the microphone.</string>
    <string>This app requires access to the camera.</string>


    2) Add code to open camera to take picture :-

    if UIImagePickerController.isSourceTypeAvailable({
                let imag = UIImagePickerController()
                imag.delegate = self
                imag.sourceType =;
                imag.allowsEditing = true
                imag.mediaTypes = [kUTTypeImage as String]
                self.present(imag, animated: true, completion: nil)


    3) Last step to use clicked image by user :-

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    //you can use image in data variable as this image is one which user picked from gallery. 
             let data = UIImagePNGRepresentation(info[UIImagePickerControllerEditedImage] as! UIImage)


 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: