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.
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.
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!
- (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];
}
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
Add this.
imgPicker.allowsEditing = YES;
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);