gpt4 book ai didi

ios 8 UIIMagePickerController 在 iPhone 6 中交替显示黑色预览屏幕

转载 作者:搜寻专家 更新时间:2023-10-30 20:17:05 24 4
gpt4 key购买 nike

在我的应用程序中,单击 UIButton 正在打开相机。打开相机后,将显示黑色预览而不是捕获图像,但可以看到重拍和使用照片按钮。此后预览显示用于 iPhone6 中的相机,但在 iPhone 5、5s 中工作正常。在我的应用程序中,一旦用户单击使用照片按钮,就会导航到其他 UIViewController。捕获的图像存储在变量中并将传递到另一个 UIViewController。从这个 UIViewController 它将发布到服务器。无法弄清楚导致黑色预览屏幕的原因。寻求帮助。以下是我的代码:

ON button click
{

[self takeNewPhotoFromCamera];

}

- (void)takeNewPhotoFromCamera
{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.allowsEditing = NO;
//controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
controller.delegate = self;
[self callOperationQue];

}

}


- (void)callOperationQue{
if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0)
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{


[self.navigationController presentViewController: controller animated: YES completion: nil];
}];

}
else
{

[self.navigationController presentViewController: controller animated: YES completion: nil];
}

}


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

[self.navigationController dismissViewControllerAnimated: YES completion: nil];

UIImage *image1 = [info valueForKey: UIImagePickerControllerOriginalImage];
// imageData = UIImagePNGRepresentation(image1);


UIImage *newImage = [self squareImageWithImage:image1 scaledToSize:sz];
imgVwProfile.image=newImage;
CGFloat compression = 0.9f;
CGFloat maxCompression = 0.1f;
int maxFileSize = 250*1024;

imageData = UIImageJPEGRepresentation(newImage, compression);

while ([imageData length] > maxFileSize && compression > maxCompression)
{
compression -= 0.1;
imageData = UIImageJPEGRepresentation(newImage, compression);
}

//passing image data to other UIViewController
CreateClaimViewController *address=[[CreateClaimViewController alloc]init];
address.img=newImage;
[self.navigationController pushViewController:address animated:NO];

}
//resizing of image
- (UIImage *)squareImageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
double ratio;
double delta;
CGPoint offset;

//make a new square size, that is the resized imaged width
CGSize sz = CGSizeMake(newSize.width, newSize.width);

//figure out if the picture is landscape or portrait, then
//calculate scale factor and offset
if (image.size.width > image.size.height) {
ratio = newSize.width / image.size.width;
delta = (ratio*image.size.width - ratio*image.size.height);
offset = CGPointMake(delta/2, 0);
} else {
ratio = newSize.width / image.size.height;
delta = (ratio*image.size.height - ratio*image.size.width);
offset = CGPointMake(0, delta/2);
}

//make the final clipping rect based on the calculated values
CGRect clipRect = CGRectMake(-offset.x, -offset.y,
(ratio * image.size.width) + delta,
(ratio * image.size.height) + delta);


//start a new context, with scale factor 0.0 so retina displays get
//high quality image
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(sz, YES, 0.0);
} else
{
UIGraphicsBeginImageContext(sz);
}
UIRectClip(clipRect);
[image drawInRect:clipRect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return newImage;
}

最佳答案

首先尝试在手机设置中检查应用程序的权限。我遇到过黑屏这样的问题,并且相机拒绝许可。我不明白这是怎么回事,因为我以为我允许拍照。

另外你最好在展示 Controller 之前检查权限

 AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

if(status == AVAuthorizationStatusAuthorized) { // authorized
[self takeFoto];
}
else if(status == AVAuthorizationStatusDenied){ // denied
[self showCameraDeniedError];
}
else if(status == AVAuthorizationStatusRestricted){ // restricted
[self showCameraDeniedError];
}
else if(status == AVAuthorizationStatusNotDetermined){ // not determined

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){ // Access has been granted ..do something
[self takeFoto];
} else {
[self showCameraDeniedError];
}
}];
}

关于ios 8 UIIMagePickerController 在 iPhone 6 中交替显示黑色预览屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26542978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com