UIImagePickerController 相机类型返回黑色图像
Posted
技术标签:
【中文标题】UIImagePickerController 相机类型返回黑色图像【英文标题】:UIImagePickerController camera type returning black image 【发布时间】:2013-10-21 07:28:58 【问题描述】:我在 UIImagePickerController 上苦苦挣扎,因为当我打开相机并拍摄图像时,它在 ios 7 中显示黑屏,因为这在 ios 6 中运行良好,我尝试了一些其他链接,但它不起作用,请帮助我解决这个问题...
我也遇到了这个错误
<Error>: CGAffineTransformInvert: singular matrix.
现在我得到了一些东西..
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.
当我点击拍照按钮时
- (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];
【问题讨论】:
当我们访问照片库但从未要求相机图像模式时,我添加了某人的提及 不,它不工作,反正我尝试了覆盖视图,它现在以某种方式工作,但仍在寻找一个体面的解决方案 【参考方案1】:我的相机也有同样的问题。我修改或编辑相机图像的屏幕显示为黑色。日志显示了同样的错误(CGAffineTransformInvert xx)。我做了很多检查以确定或知道错误在哪里。
在我的应用程序中,我使用组件 SVProgessHUD 来显示警报和消息。使用此用法注释行可以纠正问题。我已经更新到组件的最新版本(1.0)并且错误 CGAffineTransformInvert 消失了。
【讨论】:
以上是关于UIImagePickerController 相机类型返回黑色图像的主要内容,如果未能解决你的问题,请参考以下文章
SVG 覆盖在 UIImagePickerController 之上,UIImagePickerController 响应手势(iPhone/iOS)