2013-12-12 66 views
3

我開發與WinJS一個Metro應用將打開我的相機,拍照並創建一個圖片存儲Windows.Storage.StorageFile對象上的負載引起的斑點(capturedItem)我想從他們創造一個blob對象如何從Windows.Storage.StorageFile WinJS

這是我的方法:

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; 
       } 
      } 
     ); 
    } 
+2

希望這將幫助你: http://stackoverflow.com/questions/15904374/how-to-create-a-blob-object-from-image-url – Nirmal

回答

0

你實際上是非常接近。您應該首先從captureItem創建一個文件。像這樣:

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);