18

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.

4
  • stackoverflow.com/questions/39009889/… ? Commented Oct 17, 2016 at 12:42
  • 1
    its a swift version. also i worked with new delegate method.but not working. Commented Oct 17, 2016 at 12:43
  • how you have solved this ?? Commented May 25, 2017 at 16:41
  • i couldnt solve it yet.. Commented May 29, 2017 at 4:07

6 Answers 6

34

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.

Sign up to request clarification or add additional context in comments.

3 Comments

there is a problem, when I'm picking the IMAGE and then let imageData = UIImageJPEGRepresentation(theImage, 1) to send it via POST HTML I'm receiving this error and the image is not uploaded
@BogdanBogdanov But that has nothing to do with the warning. If you have a question about whatever it is you're trying to do, ask it as a question so you can show your code and we can help.
Hi @Chisx I've never seen this warning actually halt the program, sorry.
4

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!

Comments

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

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
-1

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

1 Comment

The warning is generated before the UIImagePickerControllerDelegate method is called. Therefore the exact signature of the method has nothing to do with the matter.
-2

Add this.

imgPicker.allowsEditing = YES;

1 Comment

plist add privacy-photo Library usage description.
-4

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);

1 Comment

Can you please explain it how it work with my question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.