[英]UIWebview - Loading PNG image - got error
我正在嘗試在UIWebview中加載image(png)。 但是我收到以下錯誤““ ImageIO:PNGinvalidliteral / lengths set”
我將從網絡服務中獲取“ png”。 我將其存儲在以下路徑中。 “用戶/ XXX /庫/應用程序支持/ iPhone模擬器/4.3.2/Applications/E4DE3097-EA84-492F-A2A7-5882202F3B00/Documents/attachement.png”
當我從路徑中讀取文件時,出現錯誤。 我正在使用以下代碼
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];
請幫我。
謝謝吉里嘉
如果已將“圖像”保存在“文檔”文件夾中,為什么要從MainBundle中提取圖像。 從文檔目錄中獲取圖像將是:
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.