[UWP] [HTML]访问网络共享上的图像 [英] [UWP][HTML]Accessing images on a network share
问题描述
我正在尝试在Windows 10的javascript / HTML / CSS中构建一个UWA。
I am trying to build a UWA in javascript/HTML/CSS for Windows 10.
我只是想在我的html页面中显示单个图像但每个提议的方案都给我一个错误!
I am just trying to display a single image at this time in my html page but every proposed scheme gives me an error!
在html页面中:
<img title="Enemy" src="file:///NAS-DLINK/Video/Fantasy/Enemy.jpg">
< img title =" Enemy" src =" ms-appx://///NAS-DLINK/Video/Fantasy/Enemy.jpg">
<img title="Enemy" src="ms-appx://///NAS-DLINK/Video/Fantasy/Enemy.jpg">
< img title =" Enemy" src =" ms-appx-web://///NAS-DLINK/Video/Fantasy/Enemy.jpg">
<img title="Enemy" src="ms-appx-web://///NAS-DLINK/Video/Fantasy/Enemy.jpg">
HTML1300:导航发生。
index.html
APPHOST9623:应用程序无法解析ms- appx://7ce762c9-6d04-4480-a83b-6a0b0147a8bb///NAS-DLINK/Video/Fantasy/Enemy.jpg因为这个错误:DATA_NOT_AVAILABLE。
$
APPHOST9623:应用程序无法解析ms-appx-web:// 7ce762c9-6d04-4480-a83b-6a0b0147a8bb///NAS-DLINK/Video/Fantasy/Enemy.jpg因为此错误:DATA_NOT_AVAILABLE。
HTML1300: Navigation occurred.
index.html
APPHOST9623: The app couldn’t resolve ms-appx://7ce762c9-6d04-4480-a83b-6a0b0147a8bb///NAS-DLINK/Video/Fantasy/Enemy.jpg because of this error: DATA_NOT_AVAILABLE.
APPHOST9623: The app couldn’t resolve ms-appx-web://7ce762c9-6d04-4480-a83b-6a0b0147a8bb///NAS-DLINK/Video/Fantasy/Enemy.jpg because of this error: DATA_NOT_AVAILABLE.
"文件"链接在任何浏览器中都有效。我正在访问的文件夹是使用FolderPicker选择的并存储在应用程序中。我可以访问并列出javascript代码中的所有子文件夹和文件。
The "file" link does work in any browser. the Folder I am accessing was selected with the FolderPicker and stored in the app. I can access and list all sub-folders and files in javascript code.
是否可以简单地生成< img src =" *">的列表在西澳大学的元素?
Is it possible to simply generate a list of <img src="*"> elements in a UWA ?
我希望我只是遗漏了一些简单的东西!
I hope I am just missing something simple!
提前感谢您的帮助!
推荐答案
>> 我只是试图在我的html页面中显示单个图像但是每个建议的
方案都会给我一个错误!
  ; &NBSP; 据我所知,在UWP中,无法使用任何方案直接从网络共享加载图片。
As far as I know,in UWP it is not possible to load image directly from a network share using any scheme.
>> 我使用FolderPicker选择了我正在访问的文件夹并将其存储在应用程序中。
我可以访问并列出javascript代码中的所有子文件夹和文件。
&NBSP; 您可以从JS中的文件夹中获取图像文件,并将其设置为< img>的来源。在你的js代码中如下:
You can get the image file from the folder in JS and set it as source of your <img> in your js codes like below:
document.getElementById("myBtn").onclick = function () {
var Pickers = Windows.Storage.Pickers;
var picker = new Pickers.FolderPicker();
picker.fileTypeFilter.append(".png");
picker.pickSingleFolderAsync().then(function (folder) {
folder.getFileAsync("image01.png").then(function (file) {
var htmlFile = MSApp.createFileFromStorageFile(file);
if (FileReader && htmlFile) {
var fr = new FileReader();
fr.onload = function () {
document.getElementById("myImg").src = fr.result;
}
fr.readAsDataURL(htmlFile);
}
}, onerror);
}, onerror);
}
function onerror(msg) {
console.log(msg);
}
和Html:
<body>
<button id="myBtn">Click Me</button>
<img id="myImg" />
<script src="js/main.js"></script>
</body>
最好的问候,
Elvis Xia
Elvis Xia
这篇关于[UWP] [HTML]访问网络共享上的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!