创build一个未知types的图像格式是Objective-C Xcode 8错误
从iOS 10
Objective-C
和Xcode 8
的图像select器中select图像时。 我收到一个错误 –
创build一个未知types的图像格式是一个错误
。
以前的版本可以。
这是我的代码:
UIImagePickerController* imgPicker=[[UIImagePickerController alloc] init]; imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imgPicker.delegate = self; [self presentViewController:imgPicker animated:YES completion:nil];
和委托方法来收回的形象是..
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:NULL]; UIImage *myImage = [info objectForKey:UIImagePickerControllerOriginalImage]; }
我也试过其他委托function..
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ }
但错误不会。
我不确定是Xcode 8的bug吗?
如果有人遇到问题并解决,请帮忙解决。
这是一个错误。 这只是一个虚假的警告。 应用程序的工作没有坏事,所以忽略警告。
我通过苹果文件,并使用此
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
在didFinishPickingMediaWithInfo方法中。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; imageViewPreview.image = chosenImage; [picker dismissViewControllerAnimated:YES completion:NULL]; }
希望这个帮助!
- (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]; }
将UIImagePickerControllerDelegate方法更新为新方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
从以前的方法:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
这为我解决了这个问题。 IDE版本:Xcode8.2.1
添加这个。
imgPicker.allowsEditing = YES;
我通过在CGContextRef context
variables中添加以下BitmapInfo
参数初始化来解决此问题:
CGBitmapInfo bitmapInfo = kCGImageAlphaNoneSkipLast;
而不是CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
PS:
所以现在我的CGContextRef context
如下所示
CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, CGImageGetBitsPerComponent(imageRef), 0, colorSpace, bitmapInfo); CGColorSpaceRelease(colorSpace);