相机预览黑色

时间:2015-04-21 06:35:25

标签: ios objective-c iphone camera

我正在从相机拍照。他们显示我快照未渲染的视图会导致空白快照。确保在屏幕更新后快照或快照之前,您的视图至少呈现过一次。

-(IBAction)choosePicture:(id)sender
{
    UIImagePickerController *imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.delegate=self;
    [self presentViewController:imagePicker animated:YES completion:nil];


}
-(IBAction)takePicture:(id)sender
{
    UIImagePickerController *imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;

    [self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
  //  UIImage *pickedImage=[info objectForKey:UIImagePickerControllerOriginalImage];

    image.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    picker.modalPresentationStyle = UIModalPresentationFullScreen;


    [picker dismissViewControllerAnimated:YES completion:nil];

}

2 个答案:

答案 0 :(得分:1)

在一个空的应用程序中尝试过您的代码,没有消息,一切都很好。

除了从apple https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html

下载的示例

它有同样的问题,但一切正常。可能只是一个bug。 (如果他们自己的代码有相同的消息)

如果您有此消息且某些内容无效,请尝试类似的问题。例如:UIImagePickerController error: Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7

答案 1 :(得分:1)

这对我有用:

-(IBAction)takePicture:(id)sender
{
    UIImagePickerController *imagePickController=[[UIImagePickerController alloc]init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
       imagePickController.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    else
    {
       imagePickController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    imagePickController.delegate = self;
    imagePickController.allowsEditing = TRUE;
    [self presentViewController:imagePickController animated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  [self dismissViewControllerAnimated:YES completion:nil];
  <your image> = [info objectForKey:UIImagePickerControllerEditedImage];
}