Chapter 36

Using the Camera and Photo Library

All iOS devices, with the exception of the first-generation iPad, have at least one camera. When a user takes a picture with the camera, the image is stored in the device’s photo library. This lesson shows you how to allow the user to pick an image from the photo library or take a new picture with the camera and use it in your application.

The UIKit framework contains a class called UIImagePickerController designed specifically to allow you to access the camera and photo library from your applications. This class presents its own user interface (Figure 36-1) that allows a user to browse through the photo library or control the camera. All you have to do is present this view controller in your application and provide a delegate method whose methods are called when the user has finished selecting an image.

The image picker controller can also be used to record videos and access these recorded videos within your application. Video recording and playback is not covered in this book.

Creating an instance of the UIImagePickerController is a simple matter of sending it an alloc and init message:

UIImagePickerController* imagePicker = [[UIImagePickerController alloc] 
                                        init];

The UIImagePickerController class can be used to access the contents of either the photo library, saved photos album, or the camera. You can specify the source ...

Get iPhone and iPad App 24-Hour Trainer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.