It is really easy. Your code will be in a subclass UIViewController, even if this class complies with the protocol UIImagePickerControllerDelegate, this allows your controller to receive images from the camera and / or user library.
Now you need to create and display UIImagePickerController, this controller can be used to select images from the user library and to capture images / videos from 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 the documentation for UIImagePickerControllerhow to configure it if necessary.
Then you need to get an image that the user selects or takes with the camera. This is done by implementing the method imagePickerController:didFinishPickingMediaWithInfo:from the protocol UIImagePickerControllerDelegate.
-(void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingMediaWithInfo:(NSDictionary*)info {
UIImage* image = [info objectForKey: UIImagePickerControllerOriginalImage];
}
And it's all.
source
share