获取intentExtra图像并将其显示在WebView中
我试图将来自列表视图单击上的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Noel 是正确的,它应该是
src=\"
而不是src=\\"
但无论如何它都不会工作,因为myDrawableId
是一个整数资源 ID 而不是有效的文件名(是的,我记得你的最后一个问题)。为此,只需将图像放入 /res/assets 文件夹中,而不是在意图中传递资源 ID,而是传递图像文件名,例如 my_image.jpg
示例...
Noel is correct that it should be
src=\"
and notsrc=\\"
but it's not going to work anyway asmyDrawableId
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...
我认为你的问题是你正在转义反斜杠而不是这一行中的引号:
它实际上应该是这样的:
I think your problem is that you are escaping the backslash and not the quote in this line:
It should really be this:
我很确定您想要
webview.loadUrl(data);
。是这样吗?
I'm pretty sure you want
webview.loadUrl(data);
.Is that it?