Harsha M V
Harsha M V

Reputation: 54959

Android Load Image in Web View

I am trying to use the Web view to use the pinch and zoom of an image like in a gallery.

String imageUrl = "file:///local/dir/image.jpg"; // http://example.com/image.jpg
WebView wv = (WebView) findViewById(R.id.yourwebview);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl(imageUrl);

XML

<WebView android:id="@+id/yourwebview"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent" />

Now if i want to reference an image elephant.jpg in the res\drawable-hdpi folder. How can i do it in the Activity ?

Upvotes: 1

Views: 729

Answers (1)

toadzky
toadzky

Reputation: 3846

If it's in the resource folder, you will need to convert the resource drawable into a bitmap, then write the Bitmap out. Here is how to convert to a Bitmap, and you can write it to internal storage easily enough.

If you are just looking to display a picture with zoom, etc., you may want to try something like:

Intent i = new Intent(ACTION_VIEW);
i.setDataAndType(imageUri, "image/*");
startActivity(i);

This shows you how to build a Uri for a resource image - which you might be able to use in your webview solution.

Upvotes: 2

Related Questions