how to convert a WebView into an ImageView?
i have a WebView of an html page which shows only one image
http://www.google.fr/intl/en_com/images/srpr/logo1w.png
webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("http://www.google.fr/intl/en_com/images/srpr/logo1w.png");
is there a simple way to开发者_如何学C turn it into an ImageView ?
try this:
webView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
imageView.setImageBitmap(bmap);
You can open an InputStream
pointing to the image URL (using URLConnection
), and create a Drawable
from it using Drawable.createFromStream
. You can then set the Drawable
onto the ImageView
.
As per your above comment: ok you are right it must be easier getting the image directly... how do i do that ? Do i look in bitmap doc ?
, i assume you want to load image from web and want to display the same in imageview, if this is the case then refer this to get exactly: How to display image from URL on Android
Bitmap btmp = mwebview.getDrawingCache(true);
this will return the Bitmap image in webview.
And the bitmap can be set to image view by:
imageView.setImageBitmap(bmap);
精彩评论