我有一个从 URL 下载和显示图像的应用程序。这很好用
URLConnection conn = urls[i].openConnection();
conn.connect();
if(conn.getContentLength() > 0)
is = conn.getInputStream();
bis = new BufferedInputStream(is);
Bitmap temp = BitmapFactory.decodeStream(bis);
我注意到 WebView 的下载和显示图像比上面的代码快得多,所以我想我会尝试。
String url = "http:\\image.jpg"
int mWidth = getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay().getWidth()
webView.loadData("<html><body> <img src=\"" + url + "\" width=\"" + mWidth + "px\" height=\"auto\"></body></html>", "text/html", null);
尽管这样可以更快地获取图像,但它不会将图像缩放到屏幕大小,但大图像总是超出 WebView 的宽度,需要滚动才能正确查看。
有谁知道我如何解决问题以在 WebView 中正确显示图像,或者如何首先加快图像的下载速度?
我希望加快下载速度,但如果我可以正确缩放图像,我很乐意使用 WebView。