javascript - 如何从 Windows.Storage.StorageFile WinJS 加载 blob

标签 javascript image visual-studio-2012 blob winjs

我正在使用 WinJS 开发一个 Metro 应用程序,它可以打开我的相机,拍摄并创建一张图片,将结果存储在 Windows.Storage.StorageFile 对象 (capturedItem) 我想从它们创建一个 blob 对象

这是我的方法:

 function imageCapture() {

        var captureUI = new _capture.CameraCaptureUI();

        captureUI.photoSettings.format = _capture.CameraCaptureUIPhotoFormat.jpeg;
        captureUI.captureFileAsync(_capture.CameraCaptureUIMode.photo)
            .then(function (capturedItem) {
                if (capturedItem) {

                    var photoBlobUrl = URL.createObjectURL(
                        capturedItem,
                        { oneTimeOnly: true });

                    imageElement = document.createElement("img");
                    imageElement.id = "img1";
                    imageElement.setAttribute("src", photoBlobUrl);

                    _divPicture.appendChild(imageElement);

                    // prints in textfield blob value
                    document.getElementById("field1").value = capturedItem.path;
                }
            }
        );
    }

最佳答案

您实际上非常接近。您应该首先从 capturedItem 创建一个文件。像这样:

var file = MSApp.createFileFromStorageFile(capturedItem);
// than use the file variable in the createObjectURL function
var url = URL.createObjectURL(file, { oneTimeOnly: true });
var imageElement = document.createElement("img");
imageElement.id = "img1";
imageElement.setAttribute("src", url);
_divPicture.appendChild(imageElement);

关于javascript - 如何从 Windows.Storage.StorageFile WinJS 加载 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20555963/

相关文章:

javascript - 如何知道网页上正在使用什么 Javascript(行和文件)

javascript - 使用 div jquery 创建 div

javascript - 从 blob :http using javascript with no redirection 保存文件

javascript - HTML 将两个 IMG 标签合并为一个

c++ - 如何使用 FLTK in-box.get_string()

c++ - 'DLLVERSIONINFO' 将项目从 VS2008 更新到 VS2012 后出现编译错误

visual-studio-2012 - 为什么在这个例子中预取加速不是更大?

javascript - 是否有 Vim 正则表达式开始和结束单词原子 "\<"和 "\>"的 JavaScript 等价物?

javascript - Canvas : not all objects in an array of bouncing ball objects are showing up

javascript - 如何更新图像的来源