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

自古美人都是妖i 提交于 2019-12-01 04:35:48

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!