1

I'm successfully using the WebView control to render a HTML string that I'm parsing to it... It's rendering my CSS, H1, and paragraph content perfectly.

Then, I tried to add an image tag and load in an image that is already stored locally on the phone. But it can't see to find or render the image in the WebView. How do I display locally stored images in the WebView?

Here's what I have tried:

string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string localFilename = "project-" + ProjectId + ".png";
string localPath = "file://" + Path.Combine(documentsPath, localFilename);

string FinalHtml = 
    "<html><head><style>a, h1 {color:#6fb731;} h1{font-size: 1.4em;} p, body{color:#333333;}</style></head><body>" + 
    "<img src=\"" + localPath + "\" />" +
    "<h1>" + ProjectName + "</h1>" + ProjectHtml +
    "</body></html>";

ProjectsWebView.LoadData(FinalHtml, "text/html", "UTF-8");
Cheesebaron
  • 24,131
  • 15
  • 66
  • 118
Aaron
  • 1,802
  • 3
  • 23
  • 50
  • Have you tried following this: http://stackoverflow.com/questions/5051364/load-the-image-saved-in-sdcard-in-webview – jaymarvels Oct 03 '16 at 13:09
  • I got fed up trying all kinds of different paths and just read in the file into a byte[] array, then converted it to base64 encoding and threw the base64 directly into the img tag's src attribute. I.e. inline embedding - works perfectly and no file path/permissions hassles. – Aaron Oct 04 '16 at 02:54

0 Answers0