【问题标题】:Android Load Image in Web ViewAndroid 在 Web 视图中加载图像
【发布时间】:2012-11-06 01:54:33
【问题描述】:

我正在尝试使用 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\drawable-hdpi 文件夹中引用一张图片大象.jpg。如何在 Activity 中做到这一点?

【问题讨论】:

    标签: android webview pinchzoom


    【解决方案1】:

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

    如果您只是想通过缩放等方式显示图片,您可能想尝试以下方法:

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

    This 向您展示了如何为资源图像构建 Uri - 您可以在 webview 解决方案中使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-15
      • 2011-02-26
      • 2014-10-04
      • 2010-11-14
      • 1970-01-01
      • 2020-03-18
      相关资源
      最近更新 更多