我想要一个能够将图像捕获到本地文件的摄像机视图,或者让用户从本地照片库中选择一个图像。我想也许有人为此编写了很好的库/代码。也许我可以利用它。有没有好的?谢谢。我只是避免重新发明轮子:)
答案 0 :(得分:3)
UIImagePickerController内置于iOS中,非常易于使用,它可以实现您想要的所有功能。
让用户拍摄新照片:
“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];
}
或者从设备中选择现有照片:
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] ) return;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
请务必加入此内容!
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
}