我将从图像选择器中拉出的图像保存到mysql数据库中,我检索了图像并尝试从中创建uiimage
[self.currentPicView setImage:[[UIImage alloc] initWithData:[[Person person] current_pic]]];
它给了我错误:
<Error>: ImageIO: PNG [5C][30][0D]I: invalid chunk type
<Error>: ImageIO: PNG [5C][30][0D]I: invalid chunk type
没有崩溃..图像只是不显示。我不知道该错误是什么意思或如何解决。有任何想法吗?
ps:
[[Person person] current_pic]
包含PNG图像数据。Person是单例。current_pic是Person中的NSData属性。我不能包含该代码,因为该属性是综合属性,因此我没有自己创建或覆盖该方法。
要准备和上传(通过POST使用EPUpload从此处)图像,我要做的是:
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image= [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *webData = UIImagePNGRepresentation(image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"temp-file"];
[webData writeToFile:localFilePath atomically:YES];
NSLog(@"localFilePath.%@",localFilePath);
[self doUpload:localFilePath];
[[picker parentViewController] dismissViewControllerAnimated:YES completion:^{}];
}
更新:当我使用'webData'在didFinishPickingMedia方法中构造UIImage时,它没有给出错误,并且图像没有错误。
我尝试使用POST将相同的webData直接上传到服务器,然后检索它并尝试从中创建另一个图像,并再次出现错误
通过将其作为Base64String与服务器之间来回发送,可以避免这些错误
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句