Android: Easiest way to make a WebView display a Bitmap?

后端 未结 2 373
暗喜
暗喜 2021-01-12 11:57

I have some images that I loaded from a remote source stored in Bitmap variables and I want to display them. In addition to switching between these images the user should al

相关标签:
2条回答
  • 2021-01-12 12:05

    You can just use webview to directly view your image remotely. You do not need to save anymore the image in a file. Here is a sample code snippet.

    myWebView.getSettings().setBuiltInZoomControls(true); //to get zoom functionalities
    
    String url = "http://....."; //url of your image
    
    String x= "<html><head><meta name=\"viewport\" content=\"width=device-width, minimum-scale=1.0\"/><style type=\"text/css\">html, body {margin: 0;padding: 0;} img {border: none;}</style><head><body style=\"background: black;\"><table><tr><td align=\"center\"><img src=\"" + url + "\" /></td></tr></table></body></html>";
    
    myWebView.loadData(x, "text/html", "UTF-8");
    

    About switching images, you can just change the value of the url and call the loadData again of the webview.

    0 讨论(0)
  • 2021-01-12 12:12

    I wasn't satisfied with WebView after all so I ended up creating my own image viewing Activity. Further descriptions on how I did it can be found in this post on google groups.

    0 讨论(0)
提交回复
热议问题