2

我曾AVCaptureSession在 iPhone 应用程序中用于拍摄照片。我也想从 PhotosLibrary 中获取图像。

我已经实现UIImagePickerController了控制及其所有方法。

我可以打开图书馆,但我无法获得我选择的照片。以及不调用 PickerView 的方法。这些方法没有回应。

有没有不同的方法来实现对照片库的UIImagePickerController控制?AVCaptureSession

请告诉我解决方案。

或者建议我替代解决方案,而不是Overlay因为我想要具有动态控件的两种功能。

提前致谢。

4

1 回答 1

2

对于打开的照片库,请使用:

-(IBAction)pickphoto:(id)sender
{
    [self startMediaBrowserFromViewController: self usingDelegate: self];
}

- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
                               usingDelegate: (id <UIImagePickerControllerDelegate,
                                               UINavigationControllerDelegate>) delegate{

    if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
        || (delegate == nil)
        || (controller == nil))
        return NO;

    UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
    mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie,kUTTypeImage, nil];
    mediaUI.allowsEditing = YES;

    mediaUI.delegate = delegate;

    [controller presentModalViewController: mediaUI animated: YES];
    return YES;

}

- (void) imagePickerController: (UIImagePickerController *) picker
 didFinishPickingMediaWithInfo: (NSDictionary *) info
{

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
 thumbnail = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
 [self dismissModalViewControllerAnimated:YES];
}

对于捕获图像,请使用以下命令:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

imagePicker.delegate = self;

[self presentViewController:imagePicker animated:YES completion:nil];
于 2012-12-12T07:19:13.897 回答