Camera Application to Take Pictures and Save Images to Photo Album

Editor’s Note:If you would like to save the UIImage from the camera to a PNG of JPEG file versus the Photo Album, you can find an example here: Save UIImage Object as a PNG or JPEG File. Also, to email an image from the camera, take a look at this example: How to Send Email with Attachments – Example Using iPhone Camera to Email a Photo

It’s surprising easy to create a bare bones camera application on the iPhone. UIImagePickerController provides a means to access the camera, take a photo and preview the results. There is also an option to allow resizing and scaling of a photo once captured. Using UIImageWriteToSavedPhotosAlbum in the UIKit, you can easily save an image to the Photo Album.

The image on the left in the figure below shows the camera active in the application. The image on the right is the preview option once a photo has been taken.

Start the Camera

To work with the camera we begin by creating a UIImagePickerController object and setting the sourceType to UIImagePickerControllerSourceTypeCamera. For this example, I set allowsImageEditing to NO to disable editing of photos image. I use presentModalViewController to initiate the display of the camera.

// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image ?
imagePicker.allowsImageEditing = NO;
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
Save Image to Photo Album

Once a photo has been taken, the method didFinishPickingMediaWithInfo will be called, providing the opportunity to write the image to the Photo Album:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  // Access the uncropped image from info dictionary
  UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
  // Save image
  UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
  [picker release];

Notice the call selector reference above, this selector will be called once the image has been written to the system. For this example I display an alert showing the result of attempting to save the image:

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
  UIAlertView *alert;
  // Unable to save the image  
  if (error)
    alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                            message:@"Unable to save image to Photo Album." 
                            delegate:self cancelButtonTitle:@"Ok" 
  else // All is well
    alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                            message:@"Image saved to Photo Album." 
                            delegate:self cancelButtonTitle:@"Ok" 
  [alert show];
  [alert release];
Optional Updates

This is a good, if not simple, place to start. Here are two additional updates to this application you can tinker with:

#1 – Check for a camera on device. Refer to this post Does iPhone Support Camera to learn more.

#2 – Set the image editing option to YES. This will require a few additional changes including a request to the information dictionary to return the cropping rectangle that was applied to the original image (see UIImagePickerControllerCropRect).

Source Code

You can download the source code for the camera application here.

Simulator Not Supported

One last note, this application will only run on an actual device as the simulator does not have camera support.


  1. Is there a why to have it save to other dir after it does this

    // Save image
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

    // Also save to


  2. Hi John,

    This is really helpful to me. Is it possible to mail that image instead of saving into Photo album.

    Please help.

  3. thanx for the guide…
    is there any way of giving the file a name, so when the user downloads the picture from the phone it will have a meaningful name? this is very important for me because i need to sync the pictures saved with other data.


  4. Hi John,
    I’m a little new to this so bear with me!
    I’m trying to use the code above to open the camera when a button is clicked. Am I right in thinking that the first para of code goes into the .h file between the curly brackets, and the second 2 para’s go into the .m file to define the method once the button is clicked – in my case…

    – (IBAction)takePhoto:(id)sender; {


    Thanks in advance

    • Hi Alan,

      If you download the source code for the project you can see how I use the code shown above in a complete working example. That is probably a good starting point in which you can modify the code to see how things work.

      Hope that helps.


  5. Fantastic work – I’ve been struggling with the Apple docs on this topic and your code was great bootstrap for me.

    Can you point me in the direction of a technique which will allow me to overlay or superimpose a frame or other “border” image while the camera is active and save the “merged” image?

    Thanks in advance.


    • JMT, interesting idea, I’m not sure off hand how to overlay an image on the camera (or if it’s possible). Anyone have any ideas?

  6. Where do you dealloc memory for the imagePicker? Do you find any leaks if you activate the camera multiple times?

  7. Hi John,

    This is what I am searching for. Thank you for this page.

  8. Hi there.

    Tried to run the app, but every time I build, I get the “The executable was signed with invalid entitlements.” error.

    I am a paid developer, so something is wrong with the zipped file.

  9. Do you (or any of the commenters here) have a sample or tutorial that shows you how to make an app that just uses the LED on the iPhone 4? I want to create a flashlight app with strobing….


  10. It looks like there is some sort of setup that prevents the button click action being called in ‘viewDidLoad’ – at least, I did it, but it didn’t work. Is anyone aware of an application or view delegate method in which instantiating the UIImagePickerController would work?

  11. John, no matter how much I appreciate your work it’ll never do justice to how great a job you are doing. Thank you.

  12. Great job, thanks for the info (I was stuck saving the images locally after invoking the camera, but not anymore) – thanks!

  13. Thanks for the post on this. Have a problem though.

    After the image is saved to the camera roll and the modalViewController is dismissed, the test_appViewController does not reappear with the button on it. Did the testing on the device, of course. Any clue as to why this is happening?

  14. Hi, great tutorial, Very simple and easy understanding. Few questions… I know this will NOT work in the simulator but tried anyways to see what would actually happen when i click the “Activate Camera” button. It crashes the app and i get the SIGABRT error.
    Should it display this error since the camera will not run in the simulator?

    Also how can i use the picture in my app instead of saving to photo gallery? Any documentation or reference much appreciated!


    • Steve,

      You will receive that error message, or something similar, when trying to access the camera in the simulator. You could put a check in there to see if the camera is available. Only allow camera access if it is available and then the app shouldn’t crash when you run it in your simulator.

      Also, you can save to your application’s documents directory. You should be able to find a lot of documentation on this if you search for NSFileManager and use that in combination with returned array from the method call NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).


  15. How to save image from my current image. I have 10 pictures reside in the folder called pages/image1.jpg etc. My app is about ipad picturebook. When user swipe it goes to a new page. Below the page, i have a button to save a picture to photos album. How to do that ? Any tutorial for this ?

  16. Great tutorial,

    I have integrated this into an app in which a have a view with the take picture button. When the button is pressed the camera is launched, I take the photo, and then save it to photo album. the message that it has been saved pops up and I click OK. Here is where the problem arrises. I am stuck in this view. How do I return to the view where I first pressed the take photo button? Thanks for all the help so far.

    • Typically you pop a view controller to return to the previous view, it depends how the view controller was shown. Look into the view controller documentation that Apple has, it describes all this in great detail.

  17. When I first read the article I took note of the original time stamp and almost left. I scrolled down to the comments and saw it had comments (with answers!) even two years down the road. Big thumbs up to the community and the author. RSS subscription time!

    • Holy wowzers. I decide I want to subscribe so I scroll to the top. Figuring it would take 3 or four clicks to find what I needed. Nope… it’s right there at the top. I love you guys.

  18. Thnx Bade…
    Nice tutorial…. simple and nice…. provide some more samples like this…

Comments are closed.