ios 创建一个未知类型的图像格式是一个错误 Objective-C Xcode 8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40086636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 10:36:18  来源:igfitidea点击:

Creating an image format with an unknown type is an error Objective-C Xcode 8

iosobjective-cuiimagepickercontrollerxcode8ios10

提问by riaz hasan

While choosing an image from the image picker in iOS 10Objective-Cand Xcode 8. I am getting an error -

iOS 10Objective-C和 中从图像选择器中选择图像时Xcode 8。我收到一个错误 -

Creating an image format with an unknown type is an error

创建未知类型的图像格式是错误的

.

.

It was ok for the previous version.

以前的版本没问题。

Here is my code:

这是我的代码:

UIImagePickerController* imgPicker=[[UIImagePickerController alloc] init];
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imgPicker.delegate = self;
[self presentViewController:imgPicker animated:YES completion:nil];

and the delegate method to recive the image is..

和接收图像的委托方法是..

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
       [picker dismissViewControllerAnimated:YES completion:NULL];
       UIImage *myImage = [info objectForKey:UIImagePickerControllerOriginalImage];
}

I also tried other delegate function..

我还尝试了其他委托功能..

 -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
}

but error not going.

但错误不会发生。

I am not sure is it the bug of Xcode 8?
If any one faced the issue and solved please help to fix it.

我不确定这是 Xcode 8 的错误吗?
如果有人遇到问题并解决了,请帮助修复它。

回答by matt

It's a bug. It's just a false warning. No bad thing is happening to the working of the app, so ignore the warning.

这是一个错误。这只是一个错误的警告。应用程序的工作没有发生坏事,所以忽略警告。

回答by Dharmesh Mansata

i go through apple document and use this

我浏览了苹果文档并使用了这个

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];

in didFinishPickingMediaWithInfomethod.

didFinishPickingMediaWithInfo方法中。

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

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];  
imageViewPreview.image = chosenImage;  

[picker dismissViewControllerAnimated:YES completion:NULL];     

}

hope this help!

希望这有帮助!

回答by clody

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
  UIImage *tempImage = [info objectForKey:UIImagePickerControllerEditedImage];
  UIGraphicsBeginImageContext(tempImage.size);
  [tempImage drawInRect:CGRectMake(0, 0, tempImage.size.width, tempImage.size.height)];
  UIImage *image = [UIImage imageWithCGImage:[UIGraphicsGetImageFromCurrentImageContext() CGImage]];

  [self.myimageview setImage:image];
  UIGraphicsEndImageContext();
  [picker dismissViewControllerAnimated:YES completion:nil];
}

回答by Keesara Sriramreddy

Update the UIImagePickerControllerDelegate method to the new method

将 UIImagePickerControllerDelegate 方法更新为新方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info

FROM THE PREVIOUS METHOD:

从以前的方法:

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

This fixed the issue for me. IDE Version: Xcode8.2.1

这为我解决了这个问题。IDE 版本:Xcode8.2.1

回答by Jr2000

Add this.

添加这个。

imgPicker.allowsEditing = YES;

回答by ArtStyle

I solved this problem by adding following initialisation of BitmapInfoparameter which used in CGContextRef contextvariable:

我通过添加以下变量BitmapInfo中使用的参数初始化解决了这个问题CGContextRef context

CGBitmapInfo bitmapInfo = kCGImageAlphaNoneSkipLast;

instead of CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);

代替 CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);

P.S:

PS:

So now my CGContextRef contextlooks as following

所以现在我CGContextRef context看起来如下

CGContextRef context = CGBitmapContextCreate(NULL,
        imageSize.width,
        imageSize.height,
        CGImageGetBitsPerComponent(imageRef),
        0,
        colorSpace,
        bitmapInfo);
CGColorSpaceRelease(colorSpace);