简体   繁体   English

UIWebview-加载PNG图像-错误

[英]UIWebview - Loading PNG image - got error

I am trying to load the image(png) in UIWebview. 我正在尝试在UIWebview中加载image(png)。 But I got the following error ""ImageIO: PNGinvalid literal/lengths set" 但是我收到以下错误““ ImageIO:PNGinvalidliteral / lengths set”

I will get the "png" from the web service. 我将从网络服务中获取“ png”。 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 " “用户/ XXX /库/应用程序支持/ iPhone模拟器/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 谢谢吉里嘉

If you have saved the Image in Documents Folder, why are you fetching from MainBundle. 如果已将“图像”保存在“文档”文件夹中,为什么要从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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM