This is truly easy. Your code will be in a subclass of UIViewController
, let this class conform to the UIImagePickerControllerDelegate
protocol, this allows your controller to receive images from the camera and/or users library.
Now you have to create and display a UIImagePickerController
, this view controller can be used for both selecting images from the users library, and taking images/video with the camera. Implement something like this:
-(IBAction)takePictureWithCamera {
UIImagePickerController* controller = [[UIImagePickerController alloc] init];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
[controller release];
}
This will display the image picker, see documentation for UIImagePickerController
for how to customize further if needed.
Next you need to receive the image the user picks, or takes with the camera. This is done by implementing the method imagePickerController:didFinishPickingMediaWithInfo:
from the UIImagePickerControllerDelegate
protocol.
-(void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingMediaWithInfo:(NSDictionary*)info {
UIImage* image = [info objectForKey: UIImagePickerControllerOriginalImage];
// Do stuff to image.
}
And that is it.