如何从图像URL创建Blob对象? [英] How to create a Blob object from image url?

查看:733
本文介绍了如何从图像URL创建Blob对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Winjs(javascript for windows 8 app)。
我想要的是通过给出路径从静态图像的特定URL创建一个简单的blob对象。
解决方案是什么?
任何帮助将不胜感激。

I am using Winjs(javascript for windows 8 app). what I want is to create a simple blob object from a specific url of my static image by giving the path. What is the solution? Any help will be appreciated.

推荐答案

'MSApp.CreateFileFromStorageFile()`将在下面使用。如果需要使用WinJS.xhr()发送文件,可以在xhrOptions中设置为数据。

'MSApp.CreateFileFromStorageFile()` as used below will work. if you need to send the file using WinJS.xhr() you can set as data in 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)
        {

        });

参考链接,以防你想要将blob上传到azure。要将blob发送到您的Web服务,代码将在这些行上。

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.

这篇关于如何从图像URL创建Blob对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆