Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式

Windows 8 app (html & Javascript) : alternate way to show image from picture library (other that file picker)

本文关键字:选择器 文件 显示 图像 方式 另一种 显示图 html 应用程序 amp Windows8      更新时间:2023-09-26

我一直在尝试创建一种替代方法来在listview中获取和显示图像(我指的是文件选择器以外的方法),因为应用程序加载和处理已经花费了太多时间。事实证明,我一直在错失一分。。img不采用绝对路径作为源(src)。

我使用的代码是:

var pictureLibrary = Windows.Storage.KnownFolders.picturesLibrary;
pictureLibrary.getFilesAsync(query).then(function (items) {....};

数据绑定是正确的,listview正在获取包括文件路径在内的所有文件数据。这没问题。尽管visual studio提示文件(base.js)在使用图像标签的绝对路径时出现异常:

"0x80004004 - JavaScript runtime error: Operation aborted
If there is a handler for this exception, the program may be safely continued."

那么,如果处理了异常,问题会解决吗?或者是没有办法在HTML的img标签中显示pictureLibrary中的图像(在listview中也是如此)?

有没有其他方法可以从pictureLibrary获取图像?还有一件事。。。更好的方法是:使用文件选择器或直接使用文件数据加载(即我在这里尝试的方法)。

谈到javascript,我有点天真,所以请描述一下。如果我遗漏了任何信息,请告诉我。

所以我的理解是items保存图片库中的图像。然后你可以用以下方式显示它们:

for (var i = 0; i < items.length; i++) {
    var image = document.createElement("img");
    image.src = URL.createObjectURL(items[i]);
    container.appendChild(image); // container is where you want to append them
}

我用了下面的例子。