选择图像时出错:" [通用]创建具有未知类型的图像格式是错误"

时间:2016-12-27 23:28:19

标签: ios objective-c uiimageview uiimage uiimagepickercontroller

从图像库中选择图像时,我无法解决以下错误:

[Generic]创建具有未知类型的图像格式是错误

这是我的代码:

-(void)touchPhoto:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{

NSLog(@"Photo touched");

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[picker setModalPresentationStyle:UIModalPresentationFullScreen];

NSLog(@"Presenting imagePicker");
[self presentViewController:picker animated:YES completion:NULL];

}


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



NSLog(@"did finish");
//WHEN YOU HAVE FINISHED PICKING FROM LIBRARY OR CAMERA

UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;

self.imageView.layer.borderWidth = 0.0f;
[picker dismissViewControllerAnimated:YES completion:NULL];


//save the image added


UIImage *secondImage = [UIImage imageNamed:@"iconImageClear.png"];

NSData *imgData1 = UIImagePNGRepresentation(self.imageView.image);
NSData *imgData2 = UIImagePNGRepresentation(secondImage);

BOOL isCompare =  [imgData1 isEqual:imgData2];
if(isCompare)
{
    NSLog(@"Image View contains image.png");
}
else
{
    NSLog(@"Image View doesn't contains image.png");

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/Photos"];

    NSString *photoPath = [[NSString alloc] initWithFormat:@"%@/%@%@", dataPath, self.mealTitleTextfield.text,self.mealDescriptionTextfield.text];



    NSData *data = UIImageJPEGRepresentation(self.imageView.image, 1.0);
    [data writeToFile:photoPath atomically:YES];

}



}

调试输出:

2016-12-27 23:12:26.293膳食计划[3092:118535]照片感动 2016-12-27 23:12:26.313膳食计划[3092:118535]呈现imagePicker 2016-12-27 23:12:29.668255膳食计划[3092:118535] [通用]创建未知类型的图像格式是错误的 2016-12-27 23:12:31.682膳食计划[3092:118535]完成了

我通常不会发帖,因为通常会有答案,但我似乎无法找到答案。

提前致谢!

0 个答案:

没有答案