Android: The easiest way to make WebView display a bitmap?

I have some images that I downloaded from a remote source stored in Bitmap variables and I want to display them. In addition to switching between these images, the user should also be able to scale and pan them. My first idea was to somehow convey them using the intent of the built-in gallery application, but this is not possible. The solution, offered in several places, uses WebView because it already supports zooming and panning. My question is: how do my Bitmap data get into WebView? Do I have to write it to a file first, which I will have to delete later, or is there an easier way?

Or are there even better ways to achieve my primary goal, which displays Bitmap data as scalable and panoramic images?

+7
android bitmap zoom pan
source share
2 answers

I was still not satisfied with WebView, so I eventually created my own image viewer. Further descriptions of how I did this can be found in this post on google groups .

0
source share

You can simply use web browsing to directly view your image remotely. You no longer need to save the image in a file. Here is an example 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 simply change the value of the URL and call loadData of the web view again.

+4
source share

All Articles