Android在Web视图中加载图像

问题描述:

我正在尝试使用Web视图来使用像在图库中的图像的捏和缩放。Android在Web视图中加载图像

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" /> 

现在,如果我想在res \绘制,华电国际文件夹中引用的图像elephant.jpg。我如何在活动中做到这一点?

如果它位于资源文件夹中,则需要将可绘制资源转换为位图,然后写入Bitmap。 Here是如何转换为位图,并且可以很容易地将其写入内部存储。

如果你只是希望显示与缩放等图片,你可能会想尝试类似:

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

This向您展示如何构建一个开放的对资源的图像 - 您可能能够在你的webview解决方案中使用。