0

我想要一个将图像捕获到本地文件或让用户从本地照片库中选择图像的相机视图。我想也许有人为此编写了很好的库/代码。也许我可以利用它。已经有好的了吗?谢谢。我只是避免重新发明轮子:)

4

1 回答 1

3

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];
} 
于 2012-06-25T03:46:19.497 回答