获取intentExtra图像并将其显示在WebView中

发布于 2024-12-27 15:46:16 字数 498 浏览 2 评论 0原文

我试图将来自列表视图单击上的intent.putExtra 的图像显示到WebView 中。如果我只是将其加载到 ImageView 中,我就可以正常工作,但是 imageview 不会缩放,并且我正在查看 wbeview 上的缩放控件,

这就是我到目前为止所拥有的:

 int myDrawableId = getIntent().getIntExtra("myDrawable", -1);
        WebView webview = (WebView) findViewById(R.id.webview);
        String data = "<body>" + "<img src=\\"file:///myDrawableId\"/></body>";
        webview.loadUrl("myDrawableId");

我想知道是否有人能看到我在这里出了什么问题,因为它不断地让我的“文件”像评论一样被标记出来。谢谢

Im trying to display the image i have coming from an intent.putExtra on a listView click, into a WebView. I have it working fine if i just load it into an ImageView, but the imageview doesnt zoom and i was looking into the zoomcontrol on a wbeview

here is what i have so far:

 int myDrawableId = getIntent().getIntExtra("myDrawable", -1);
        WebView webview = (WebView) findViewById(R.id.webview);
        String data = "<body>" + "<img src=\\"file:///myDrawableId\"/></body>";
        webview.loadUrl("myDrawableId");

i was wondering if anyone could see what i had wrong here, because it keeps making my "file" tagged out like comments. thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

虫児飞 2025-01-03 15:46:16

Noel 是正确的,它应该是 src=\" 而不是 src=\\" 但无论如何它都不会工作,因为 myDrawableId 是一个整数资源 ID 而不是有效的文件名(是的,我记得你的最后一个问题)。

为此,只需将图像放入 /res/assets 文件夹中,而不是在意图中传递资源 ID,而是传递图像文件名,例如 my_image.jpg

示例...

String imageName = getIntent().getStringExtra("myDrawableName");
webview.loadUrl("file:///android_asset/" + imageName);

Noel is correct that it should be src=\" and not src=\\" but it's not going to work anyway as myDrawableId is an integer resource id and not a valid filename (yes, I remember your last question).

To do this simply put the image into the /res/assets folder and instead of passing the resource id in the intent pass the image filename, e.g., my_image.jpg

Example...

String imageName = getIntent().getStringExtra("myDrawableName");
webview.loadUrl("file:///android_asset/" + imageName);
草莓酥 2025-01-03 15:46:16

我认为你的问题是你正在转义反斜杠而不是这一行中的引号:

    String data = "<body>" + "<img src=\\"file:///myDrawableId\"/></body>";

它实际上应该是这样的:

    String data = "<body>" + "<img src=\"file:///myDrawableId\"/></body>";

I think your problem is that you are escaping the backslash and not the quote in this line:

    String data = "<body>" + "<img src=\\"file:///myDrawableId\"/></body>";

It should really be this:

    String data = "<body>" + "<img src=\"file:///myDrawableId\"/></body>";
扶醉桌前 2025-01-03 15:46:16

我很确定您想要 webview.loadUrl(data);

是这样吗?

I'm pretty sure you want webview.loadUrl(data);.

Is that it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文