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

这一生的挚爱 提交于 2019-11-26 22:57:23

问题


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

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.


回答1:


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.




回答2:


i go through apple document and use this

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];

in didFinishPickingMediaWithInfo method.

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

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

[picker dismissViewControllerAnimated:YES completion:NULL];     

}

hope this help!




回答3:


- (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];
}



回答4:


Update the UIImagePickerControllerDelegate method to the new method

- (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




回答5:


Add this.

imgPicker.allowsEditing = YES;



回答6:


I solved this problem by adding following initialisation of BitmapInfo parameter which used in CGContextRef context variable:

CGBitmapInfo bitmapInfo = kCGImageAlphaNoneSkipLast;

instead of CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);

P.S:

So now my CGContextRef context looks as following

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


来源:https://stackoverflow.com/questions/40086636/creating-an-image-format-with-an-unknown-type-is-an-error-objective-c-xcode-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!