简体   繁体   中英

iOS camera capture view already?

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 :)

UIImagePickerController is built into iOS and very easy to use, it allows for all the functionally you want.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

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];
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM