我想要一个可以将图像捕获到本地文件或让用户从本地相册中选择图像的相机视图。我认为也许有人为此编写了不错的库/代码。也许我可以利用它。已经有好东西了吗?谢谢。我只是避免重新发明轮子:)
最佳答案
UIImagePickerController内置于iOS中,非常易于使用,它可以满足您想要的所有功能。
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
供用户拍摄新照片:
“ 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];
}
关于iphone - iOS相机已捕获 View ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11183248/