简体   繁体   English

如何从图片网址创建Blob对象?

[英]How to create a Blob object from image url?

I am using Winjs(javascript for windows 8 app). 我正在使用Winjs(适用于Windows 8应用程序的javascript)。 what I want is to create a simple blob object from a specific url of my static image by giving the path. 我想要的是通过给定路径从我的静态图像的特定URL创建一个简单的Blob对象。 What is the solution? 解决办法是什么? Any help will be appreciated. 任何帮助将不胜感激。

'MSApp.CreateFileFromStorageFile()` as used below will work. 下面使用的'MSApp.CreateFileFromStorageFile()`将起作用。 if you need to send the file using WinJS.xhr() you can set as data in xhrOptions. 如果需要使用WinJS.xhr()发送文件,则可以在xhrOptions中设置为数据。

var uri = new Windows.Foundation.Uri('ms-appx:///images/IMG_0550.jpg');
        var self = this;
        Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function ongetfilecomplete(storageFile)
        {
            var file = MSApp.createFileFromStorageFile(storageFile);
            var url = URL.createObjectURL(file, { oneTimeOnly: true });
            // assume that this.imageElement points to the image tag
            self.imageElement.setAttribute('src', url);
        }).then(null, function onerror(error)
        {

        });

refer the link in case you are looking for upload the blob to azure. 请参考链接 ,以防您将斑点上传到天蓝色。 For send the blob to your webservice also, code will be on these lines. 为了将Blob也发送到您的Web服务,代码将在这些行上。

URL.createObjectURL("") should work. URL.createObjectURL(“”)应该可以。 I use it all the time. 我用它所有的时间。 Test it with some other URLs. 使用其他一些URL对其进行测试。 You could do it in debug mode in the JS console to make it easier. 您可以在JS控制台中以调试模式进行操作,以使其更容易。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM