0

I am trying to load the image(png) in UIWebview. But I got the following error ""ImageIO: PNGinvalid literal/lengths set"

I will get the "png" from the web service. I will store it in the following path. "Users/XXX/Library/Application Support/iPhone Simulator/4.3.2/Applications/E4DE3097-EA84-492F-A2A7-5882202F3B00/Documents/attachement.png "

When I reading the file from the path, I got the error. I am using the following code

  NSBundle *bundle = [NSBundle mainBundle]; 


  NSString *path = [bundle bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];

    NSString *commentHtml = [NSString stringWithFormat:@"<img src=\"%@\"/>", documentEntity.path];
    NSString *html3 = [NSString stringWithFormat:@"<html><head/><body><div><b>COMMENTS:</b></div>%@</body></html>", commentHtml];
    [self.documentView loadHTMLString:html3 baseURL:baseURL];

Please help me.

THanks Girija

Finder
  • 8,259
  • 8
  • 39
  • 54
  • 1
    any code will help for better understanding – Saurabh Passolia May 31 '12 at 08:49
  • 1
    As samfisher said, it's hard to help without the code. Also: if you're loading an image from app bundle please upload it to your question; if you're loading it from web please provide a link. Did you try to show the same image in a UIImageView? – Rok Jarc May 31 '12 at 09:15
  • For starters try the accepted answer here: http://stackoverflow.com/questions/747407/using-html-and-local-images-within-uiwebview (ie: without the extra html). Take a look at http://stackoverflow.com/questions/3808451/how-to-embed-local-images-in-uiwebview, http://stackoverflow.com/questions/5329648/display-local-uiimage-on-uiwebview also. – Rok Jarc May 31 '12 at 09:31

1 Answers1

1

If you have saved the Image in Documents Folder, why are you fetching from MainBundle. Fetching Image from the Documents Directory would be :

    NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *aFilePath = [NSString stringWithFormat:@"%@/attachement.png", aDocumentsDirectory];
    UIImage *anImage = [UIImage imageWithContentsOfFile:aFilePath];
Roshit
  • 1,589
  • 1
  • 15
  • 37
  • Hi Thanks.. I am tried the as per your suggestion. But I am getting the error ""ImageIO: PNGinvalid literal/lengths set" and also image won't get loaded. Please help me.. THanks in advance... – Finder May 31 '12 at 09:58
  • Actullay, I am getting the image in Base64Encoded format from the service. So again I have converted Base64Decoded then write in the file path.After that I am trying to read the image, I got the error and image did not get loaded... – Finder May 31 '12 at 10:00
  • once u saved the image in the documents folder, did u check if the image was in the right format ? – Roshit May 31 '12 at 12:54
  • would be helpful if you could post the code that u used to save the image... also, the URL for the Image.. – Roshit May 31 '12 at 12:55