Android: How to Display a Bitmap in a WebView?

前端 未结 5 1218
长发绾君心
长发绾君心 2020-12-09 21:21

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)

5条回答
  •  感动是毒
    2020-12-09 22:04

    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! :-)

提交回复
热议问题