【问题标题】:What does <Error>: ImageIO: PNG [5C][30][0D]I: invalid chunk type mean?<Error>: ImageIO: PNG [5C][30][0D]I: invalid chunk type 是什么意思?
【发布时间】:2014-05-28 00:11:33
【问题描述】:

我将从图像选择器中提取的图像保存到 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 使用来自here 的 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 直接上传到服务器,然后检索它并尝试从中创建另一个图像,并再次收到错误

【问题讨论】:

  • 什么是[[Person person] current_pic]
  • @nhgrif 是一种从数据库返回数据的方法。它包含 PNG 图像数据
  • 语句越简单,错误越容易调试,不要包含那么多子语句。
  • 如果您向我们展示这段代码会非常有帮助,对吧? UIImageViewsetImage: 方法不太可能成为问题。 UIImageinitWithData: methid 也极不可能成为问题。问题在于您如何下载数据,如何通过该方法发送数据,或者图像在服务器上已损坏。
  • 所以你需要包含相当多的Person 类。 person 方法到底是做什么的,current_pic 方法到底是做什么的?你能在服务器上检查图像本身以确认它在服务器端没问题吗?

标签: ios objective-c uiimage


【解决方案1】:

当我的包中有两个同名的 png 图像时,我遇到了这个问题! orange.pngorange.png... 将第二个重命名为 citrus.png,我什至没有意识到它们至少有一个小时同名,每当我尝试加载该图像时,应用程序都会崩溃这个错误。

【讨论】:

    【解决方案2】:

    通过将它作为 Base64String 发送到服务器和从服务器发送,可以避免这些错误

    【讨论】:

      猜你喜欢
      • 2021-09-07
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 2023-04-06
      • 2014-01-12
      • 2015-10-08
      相关资源
      最近更新 更多