Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible to embedd the base64 encoded imagedata direct into the <code>&lt;img&gt;</code>-tag:</p> <pre><code> &lt;img src="data:image/jpeg;base64,base64DataHere" /&gt; </code></pre> <p>Here an example for creating the <code>&lt;img&gt;</code>-tag (I use an byte-array instead the String for raw-data, because in my tests an String as source didn't work - I assume that String can't handle binary-data):</p> <pre><code> byte[] imageRaw = yourImage; String image64 = Base64.encodeToString(imageRaw, Base64.DEFAULT); String pageData = "&lt;img src=\"data:image/jpeg;base64," + image64 + "\" /&gt;"; </code></pre> <p>The Base64-class was introduced with API v.2.2 - for older API-versions you can copy the <a href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob_plain;f=core/java/android/util/Base64.java;hb=HEAD" rel="noreferrer"><strong>sourcefile from git</strong></a> and integrate it in your app. It should work with older API-versions.</p> <p>Or you can use one of the alternative classes for base64-encoding like <a href="http://www.source-code.biz/base64coder/java/" rel="noreferrer"><strong>Base64Coder</strong></a>.</p> <hr/> <p>And here the complete working code for retrieving, converting and showing the image:</p> <pre><code> byte[] imageRaw = null; try { URL url = new URL("http://some.domain.tld/somePicture.jpg"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); ByteArrayOutputStream out = new ByteArrayOutputStream(); int c; while ((c = in.read()) != -1) { out.write(c); } out.flush(); imageRaw = out.toByteArray(); urlConnection.disconnect(); in.close(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String image64 = Base64.encodeToString(imageRaw, Base64.DEFAULT); String urlStr = "http://example.com/my.jpg"; String mimeType = "text/html"; String encoding = null; String pageData = "&lt;img src=\"data:image/jpeg;base64," + image64 + "\" /&gt;"; WebView wv; wv = (WebView) findViewById(R.id.webview); wv.loadDataWithBaseURL(urlStr, pageData, mimeType, encoding, urlStr); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload