Krunal Krunal - 4 months ago 31
iOS Question

Take picture and set it to UIImageView in iOS

Is there a way to take a picture on the iPad without going through the Apple controls ? I have seen a bunch of apps that do this,

For example, when you add a new contact in iPhone, on the top left side it shows

add photo
when we click on that, camera opens up and it takes pic and saves to
add photo
..

I want to implement same functionality.. is it possible on iPad ?

Answer

What you need to do is , Add a button first, with the title "Add Photo" or with custom image.

Then on the click of the button add the following code :

    if (([UIImagePickerController isSourceTypeAvailable:
              UIImagePickerControllerSourceTypeCamera] == NO)
            return NO;

        UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController: cameraUI animated: YES completion:nil];

It will open up the camera, then you click the image and then tap "use" and You have to implement the UIImagePickerControllerDelegate method imagePickerController:didFinishPickingMediaWithInfo: and then store the UIImage to wherever you want, with whatever file name you want, using NSFileManager methods.