gpt4 book ai didi

Android 在 Web View 中加载图像

转载 作者:行者123 更新时间:2023-11-29 21:56:04 26 4
gpt4 key购买 nike

我正在尝试使用 Web View 来像在图库中一样使用图像的捏合和缩放。

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 文件夹中的图像 elephant.jpg。我怎样才能在 Activity 中做到这一点?

最佳答案

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

如果您只是想显示带有缩放等的图片,您可能想尝试类似的方法:

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

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

关于Android 在 Web View 中加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13237366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com