Reputation: 63369
I want a camera view that will capture a image to a local file or let user select an image fro m the local photo gallery. I think maybe someone has written good library/code for that. Maybe I can leverage it. Is there any good one already? Thanks. I am just avoiding to reinvent the wheel :)
Upvotes: 0
Views: 240
Reputation: 130222
UIImagePickerController is built into iOS and very easy to use, it allows for all the functionally you want.
For the user to take a new photo:
"UIImagePicker *imagePicker
"
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES)
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:imagePicker animated:YES];
}
Or to choose an existing photo from the device:
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] ) return;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
Be sure to include this!
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
}
Upvotes: 3