简体   繁体   English

我该如何使用<img>在 Android 上使用本地图像?

[英]How can I use <img> with a local image on Android?

Using <img> with the src , a local file works fine on a PC.<img>src ,本地文件可以在 PC 上正常工作。 But on Android 7 it doesn't get displayed;但在 Android 7 上它不会显示; instead a no photo icon is displayed.而是显示无照片图标。 How can I solve this?我该如何解决这个问题?

<img src="photo.png">

(The photo.png is placed in the same folder as the .html file.) photo.png.html文件放在同一文件夹中。)

You have to declare the path of the photo:您必须声明照片的路径:

<img sc = " xxxpathxxx/"photo.png">

Else, make a separate image folder and call it.否则,创建一个单独的图像文件夹并调用它。

The issue with this is how Webview works with local files.问题在于Webview 如何处理本地文件。 File paths aren't the same as your PC Google Chrome paths where you can drag an HTML file to the browser and have it be loaded in a certain path, and because of that photo.png doesn't direct anywhere.文件路径与您的 PC 谷歌浏览器路径不同,您可以在其中将 HTML 文件拖到浏览器并在特定路径中加载,因此 photo.png 不会指向任何地方。

Instead, you need to use the file:// schema to access local files.相反,您需要使用file:// 架构来访问本地文件。 Regardless of whether photo.png is local or an Internet resource, you'll need to use photo.png's absolute path, eg:无论 photo.png 是本地资源还是 Internet 资源,您都需要使用 photo.png 的绝对路径,例如:

http://localhost/path/to/photo.png
http://www.mywebsite.com/path/to/photo.png
file://data/local/tmp/photo.png

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用require(&#39;img.jpg&#39;)在background-image样式属性内在本地服务器上加载img文件吗? - Can I use require('img.jpg') to load img file on local server within background-image style property? 如何使用本地绝对路径作为图像的src属性 - How can I use local absolute path as a src attribute for an image 如何使用另一段javascript中的img id =“ image1”在点击时弹出? - How can I use an img id=“image1” from another piece of javascript to pop up on click? 如何在html img标签中使用Java字符串图像对象-有可能吗? - How can I use a java string image object in a html img tag - Is it possible? 如何通过点击带有javascript的图像返回img.src? - How can i return img.src by clicking on an image with javascript? 如何下载使用渲染的图像<img>标签? - How can I download image which is rendered with <img> tag? 如何在图像的源标签中使用返回的字符串(React v16.0.0 的新特性):<img src='returnedString' /> ? - How Can I use the returned string (new feature of React v16.0.0) in the source tag of an image ex: <img src='returnedString' />? 如何使用正则表达式查找所有 img 属性? - How can I use regular expression find all img attribute? 如何将属性添加到img标签以在ajax调用中使用 - How can I add attributes to an img tag to use in an ajax call 如何使用img src浏览和上传图像 - How to use img src to browse and upload image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM