How to show local image in webview in android

I just want to show a local image with some texts and other materials in my android web browser.

ie i have webview st

 WebView mWebView = (WebView) otherappView.findViewById(R.id.webView1);
 String summary =readRawTextFile(context, R.raw.abc);
 mWebView.loadData(summary, "text/html", null);

and in the abc.html file, what should I write for the src image tag (???? part)

 <img width="48" height="48" src="??????" class="attachment-48x48 wp-post-image" alt="" title="analogklasik48" />

ps the project is a library project, so I do not want to use the resource folder

ps file: ///android_res/drawable/image.png not working

+5
source share
1 answer

If you want to put the image from the dropdown folder, you must convert it to base64 and then paste it into the html line:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_drawable);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
String base64Image = Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
String imgHtml = "<img src=\"data:image/jpg;base64," + base64Image + "\"/>";
+2
source

All Articles