2013-04-09 43 views
0

我正在使用Winjs(javascript for windows 8應用程序)。 我想要的是通過給出路徑從靜態圖像的特定URL創建一個簡單的blob對象。 解決方案是什麼? 任何幫助將不勝感激。如何從圖像url創建Blob對象?

回答

0

'MSApp.CreateFileFromStorageFile()`將在下面使用。如果您需要使用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) 
     { 

     }); 

指萬一link你正在尋找上傳團塊到Azure上。爲了將blob發送到您的web服務,代碼將在這些線上。

+0

我想要從存儲文件(我不想添加新功能)中得到一個圖像文件:如何在我的/ images文件夾中圖像實例化一個blob對象,甚至是一個空的Blob,我需要它與我的Web服務一起發送 – Brahim 2013-04-09 15:39:53

0

URL.createObjectURL(「」)應該工作。我用它所有的時間。使用其他一些網址進行測試。你可以在JS控制檯的調試模式下做到這一點,使其更容易。