I\'m using a WebView for displaying a map-like image, due to the built-in panning and zooming functionality. However, I need to overlay some other information (markers etc)
The answer seems to be: no, displaying a local bitmap object in a webview, without saving it to a file, is not possible.
You dont require Bitmap, just its name is enough. Try following:
html = "<html><img src=\"" + imageUrl
+ "\"></html>";
final WebView webView = (WebView) view
.findViewById(R.id.yourWebView);
wvImageView.getSettings().setJavaScriptEnabled(true);
wvImageView.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
This should display your image on WebView. If you want to provide zooming facility, try this:
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
You don't need placeholder if u want to load image in webview
You can directly load the dataurl in the webview. For ex:
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String imgageBase64 = Base64.encodeToString(byteArray, Base64.DEFAULT);
String dataURL= "data:image/png;base64," + imgageBase64;
webview.loadUrl(dataURL); //pass the bitmap base64 dataurl in URL parameter
Hope it helps others! :-)
Using the link from itsrajesh4uguys, I've created this code snippet:
// Desired Bitmap and the html code, where you want to place it
Bitmap bitmap = YOUR_BITMAP;
String html="<html><body><img src='{IMAGE_PLACEHOLDER}' /></body></html>";
// Convert bitmap to Base64 encoded image for web
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String imgageBase64 = Base64.encodeToString(byteArray, Base64.DEFAULT);
String image = "data:image/png;base64," + imgageBase64;
// Use image for the img src parameter in your html and load to webview
html = html.replace("{IMAGE_PLACEHOLDER}", image);
webview.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", "");
Normally in webview we can set the images using html tags.. this wont make any issues.
any way use this link for sample question and answer
Why Bitmap to Base64 String showing black background on webview in android?