Android: WebView doesn't scale large images
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/ht开发者_Go百科ml", "utf-8", "");
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.
Is there a way to use WebView to show a large image scaled down to for example 10%?
Pom
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.
精彩评论