简体   繁体   中英

UIImagePickerController camera type returning black image

I am struggling with UIImagePickerController as when i open camera and take image it show black screen in IOS 7 as this is working fine in ios 6, i have tried some other links what says but its not working, please help me with this...

and i am getting this error too

<Error>: CGAffineTransformInvert: singular matrix.

and now i got something ..

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

when i just click on take image button

拍摄后的图像

 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (buttonIndex == 0) {

                if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {

                    NSString *mediaType = AVMediaTypeVideo; // Or AVMediaTypeAudio



                AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];

                // This status is normally not visible—the AVCaptureDevice class methods for discovering devices do not return devices the user is restricted from accessing.
                if(authStatus == AVAuthorizationStatusRestricted){
                    NSLog(@"Restricted");
                }

                // The user has explicitly denied permission for media capture.
                else if(authStatus == AVAuthorizationStatusDenied){
                    NSLog(@"Denied");
                }

                // The user has explicitly granted permission for media capture, or explicit user permission is not necessary for the media type in question.
                else if(authStatus == AVAuthorizationStatusAuthorized){
                    NSLog(@"Authorized");

                    if  ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
                        UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
                        imagePickerCamera.delegate = self;
                        imagePickerCamera.allowsEditing = YES;
                        imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [self presentViewController:imagePickerCamera  animated:YES completion:^{}];
                        });

                    } else {

                        NSString *errorString = [NSString stringWithFormat:@"This device does not support this feature."];
                        UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                        [errorAlert show];
                    }
                }

                // Explicit user permission is required for media capture, but the user has not yet granted or denied such permission.
                else if(authStatus == AVAuthorizationStatusNotDetermined){

                    [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
                        if(granted){
                            NSLog(@"Granted access to %@", mediaType);
                        }
                        else {
                            NSLog(@"Not granted access to %@", mediaType);
                        }
                    }];

                }

                else {
                    NSLog(@"Unknown authorization status");
                }
            }

            else {
                if  ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
                    dispatch_async(dispatch_get_main_queue(), ^{
                        UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
                    imagePickerCamera.delegate = self;
                    imagePickerCamera.mediaTypes = @[(NSString *) kUTTypeImage];
                    imagePickerCamera.allowsEditing = YES;
                    imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
                        [self presentViewController:imagePickerCamera  animated:YES completion:nil];
                    });
                } else {

                    NSString *errorString = [NSString stringWithFormat:@"This device does not support this feature."];
                    UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [errorAlert show];
                }
            }


        } else if (buttonIndex == 1) {


            if  ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
                UIImagePickerController *imagePickerAlbum =[[UIImagePickerController alloc] init];
                imagePickerAlbum.delegate = self;
                imagePickerAlbum.mediaTypes = @[(NSString *) kUTTypeImage];
                imagePickerAlbum.allowsEditing = YES;
                imagePickerAlbum.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

                [self presentViewController:imagePickerAlbum animated:YES completion:nil];
            } else {

                NSString *errorString = [NSString stringWithFormat:@"This device does not support this feature."];
                UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [errorAlert show];
            }
        }
    });
}


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

[picker dismissModalViewControllerAnimated:YES];
_upLoadimage = info[UIImagePickerControllerEditedImage];

}

I had the same problem with camera. My screen to modify or editing camera image was appearing black. The log showed me same error (CGAffineTransformInvert xx ). I did a lot of checks to determine or know where is the error.

In my application I use the component SVProgessHUD to show alerts and messages. Commenting lines with this use corrects the problem. I have updated to the last version of the component (1.0) and the error CGAffineTransformInvert disappears.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM