0

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 turn it into an ImageView ?

COcdm
  • 3
  • 2
  • 4
  • 1
    Why do you want to convert webview into imageview? Instead, you can load image from web and display the same into ImageView directly. – Paresh Mayani Jul 19 '11 at 13:22
  • ok you are right it must be easier getting the image directly... how do i do that ? Do i look in bitmap doc ? – COcdm Jul 19 '11 at 13:43

4 Answers4

2

try this:

webView.buildDrawingCache();

Bitmap bmap = imageView.getDrawingCache();

imageView.setImageBitmap(bmap);
Praveen S
  • 10,355
  • 2
  • 43
  • 69
Nguyen Minh Binh
  • 23,891
  • 30
  • 115
  • 165
  • It doenst seem to be working. There is an error from the emulator. maybe it is because i m on Android 2.1 . – COcdm Jul 19 '11 at 14:14
  • How is the error? I have tried this before on android 1.6,2.1, 2.3 and it works fine. – Nguyen Minh Binh Jul 19 '11 at 14:25
  • actualy there is no error. When i run the app on the emulator the image view is just empty, as if it does not exist. – COcdm Jul 19 '11 at 15:22
  • I found a similarly answer at http://stackoverflow.com/questions/4715044/android-how-to-convert-whole-imageview-to-bitmap/4717173#4717173 and it resolved similarly problem. You should check your codes again. – Nguyen Minh Binh Jul 20 '11 at 03:08
1

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.

sparkymat
  • 9,938
  • 3
  • 30
  • 48
1

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

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0
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);
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
123
  • 37
  • 1
  • 8