winJS(CameraCaptureUI)如何预览(完成)和SAVE(?)图片到磁盘?

时间:2014-06-12 18:23:36

标签: camera windows-runtime windows-8.1 winjs

我经常研究并尝试了一些不起作用的东西。 所以我需要的是:

  1. 得到照片(工作)
  2. 显示为用户预览(工作)
  3. 在图片库中创建图像(工作)
  4. 将预览保存为本地图片文件夹(缺少)
  5. 感谢。

    我拍摄照片并在页面上显示如下:

      function captureImage()
    
    {
    
     //S1: Create a new Camera Capture UI Object
    
     var cam = Windows.Media.Capture.CameraCaptureUI();
    
     var name = document.getElementById('ticketnum').innerHTML+'.jpg';
    
     var folder = Windows.Storage.KnownFolders.picturesLibrary; //was windows.storage
    
     //S2: Perform an Async operation where the Capture
    
     // Image will be stored as file
    
    cam.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo)
    
     .done(function (data) {
    
     if (data)
    
     {
    
     //S3: Create a URL for the capture image
    
     // and assign it to the <Img>
    
     var urlpic= window.URL.createObjectURL(data);
    
    document.getElementById('imgCapture').src
    
     = urlpic;
    
     //**save picture to memory as ticket number, creating new img, how to put the file inside?
    
    folder.createFileAsync(name, Windows.Storage.CreationCollisionOption.replaceExisting) //creates new file?
    
     .then(function (file) {
    
    //file.copyAndReplaceAsync(window.URL.createObjectURL(data));
    // HOW TO SAVE IMAGE TO pictures library? 
     });
    
    
        }
    
     }
    
     , error);
    
    document.getElementById('txtserver').value = "Done";
    
     //save image to memory?
    
     //clean up resources
    
    }
    

1 个答案:

答案 0 :(得分:0)

以下是答案:

function testSavePictureDisk() {    
    // S1: Create a new Camera Capture UI Object
    var cam = Windows.Media.Capture.CameraCaptureUI();

    //location?
    var name = document.getElementById('ticketnum').innerHTML + '.jpg';

    var folder = Windows.Storage.KnownFolders.picturesLibrary; //was windows.storage

    // S2: Perform an Async operation where the Capture
    // Image will be stored as file
    folder.createFileAsync(name, 
        Windows.Storage.CreationCollisionOption.replaceExisting) //creates new file?
        .then(function (file) {
            cam.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo)
               .done(function (data) {
                    if (data) {
                        //S3: Create a URL for the capture image
                        // and assign it to the <Img>
                        document.getElementById('imgCapture').src = window.URL.createObjectURL(data);

                        //**save picture to memory as ticket number
                        data.moveAndReplaceAsync(file);

                        //**end testing for local save
                    }
                }
            , error);

        document.getElementById('txtserver').value = "Done";

        //save image to memory?
        //clean up resources
    });//end of new file creation
}

步骤

  1. 创建新文件
  2. 拍摄照片并预览
  3. 将图片移至文件