1

i saved an image pulled from image picker into a mysql database, i retrieve the image and try to create a uiimage from it with

[self.currentPicView setImage:[[UIImage alloc] initWithData:[[Person person] current_pic]]];

and it gives me the error:

<Error>: ImageIO: PNG [5C][30][0D]I: invalid chunk type
<Error>: ImageIO: PNG [5C][30][0D]I: invalid chunk type

without crashing.. the image just doesn't show. i have no idea what that error means or how to fix it. any ideas?

ps:

[[Person person] current_pic]

contains the PNG image data.. Person is a singleton. current_pic is an NSData property in Person. i can't include that code because the property is synthesized and so i didn't create the method myself or override it.

To prep and upload(via POST using EPUpload from here) the image, i do:

-(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:^{}];
}

UPDATE: When i construct a UIImage in the didFinishPickingMedia method using 'webData', it doesn't give an error and the image is create sans error.

i tried uploading that same webData directly to the server with POST, then retrieved it and attempted to create another image from it, and got the error again

Community
  • 1
  • 1
  • What is `[[Person person] current_pic]`? – nhgrif May 28 '14 at 00:12
  • @nhgrif that is a method that returns the Data from the database. it contains the PNG image data –  May 28 '14 at 00:14
  • Errors are easier to debug when statements are simpler, don't contain so many sub-statements. – zaph May 28 '14 at 00:15
  • It'd be extraordinarily helpful if you showed us this code, right? `UIImageView`'s `setImage:` method is highly unlikely to be the issue. `UIImage`'s `initWithData:` methid is also highly unlikely to be the issue. The issue is either with how you're downloading the data, how you're sending the data via the method, or the image is simply corrupted on the server. – nhgrif May 28 '14 at 00:16
  • So you need to include quite a bit of the `Person` class. What's the `person` method do exactly, and what's the `current_pic` method do exactly? And can you check the image itself on the server to confirm it's fine on the server end? – nhgrif May 28 '14 at 00:18
  • @Zaph i save the actual imageData to the database because the app requires all users to be able to see this image. also, what is and how do a hex dump? any info would be greatly appreciated –  May 28 '14 at 00:25
  • Sorry, I did not notice the database was on a server. – zaph May 28 '14 at 00:30
  • @nhgrif it looks right on the server btw,looks like: "PNG \0\0\0 IHDR\0\0,\0\0,\0\0\0^e¾\0\0\0iDOT\0\0\0\0\0\0\0\0\0\0\0\0(\0\0\0\0\0®Zn\0\0@\0IDATxܽ]ׯë?áÝÛI¿îû8AX*ffÐnºsÝ8ä8NbfÇÄA,Tª¤TçbfÖûæ{¯ÚU"... a bunch more –  May 28 '14 at 00:50

2 Answers2

1

I got this issue when I had two png images in my bundle with the same name! orange.png and orange.png... renamed the second to citrus.png, I hadn't even realized they had the same name for at least an hour, and whenever I would try to load that image, the app would crash with this error.

Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
0

by sending it to and from the server as a Base64String, these errors are avoided