安卓的WebView没有大型图片 [英] Android: WebView doesn't scale large images

查看:117
本文介绍了安卓的WebView没有大型图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的WebView显示图像:

I'm using webview to show an image:

webview.setInitialScale(10);
String myHTML = ("<html><head></head><body><img src=\"" + imgUri + "\"></body></html>");
webview.loadDataWithBaseURL("file:///android_asset/", myHTML, "text/html", "utf-8", "");

问题是,如果imgUri指向一个真正的大图像(eg.2000点¯x3000像素),那么降尺度不起作用。我认为,限制是介于30%左右,即initialScale值图像只是停留在30%左右的大小下方。因此,例如设置初值为10,20或30产生类似的图像的大小。

The problem is that if imgUri points to a really large image (eg.2000 x 3000 px) then the downscaling doesn't work. I think the limit is somewhere around 30%, underneath that initialScale value the image just stays at around 30% size. So, for example setting initialValue to 10, 20 or 30 produces similar image size.

有没有办法使用的WebView显示一个大的图像缩小到一个办法,例如10%?

Is there a way to use WebView to show a large image scaled down to for example 10%?

双龙

推荐答案

如果你有,也许尝试某种浏览器的最终大小调整通过JavaScript或CSS(如的 http://atomgiant.com/2006/05/30/resize-images-with-javascript/ )。但是,发送图像,大型过线可能会导致pretty慢的用户体验 - 如果你有以上所涉及的Web服务器的任何控制,或者如果你使用,在缩放尺寸提供图像,以及服务,尝试首先发送一个较小的版本。

If you have to, maybe try browser-end resizing of some sort via Javascript or CSS (e.g. http://atomgiant.com/2006/05/30/resize-images-with-javascript/). But sending images that large over the wire will probably result in a pretty s l o w user experience -- if you have any control over the web server involved, or if you're using a service that provides images in scaled sizes as well, try sending a smaller version in the first place.

这篇关于安卓的WebView没有大型图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆