winJS(CameraCaptureUI)如何预览(完成)并将(?)图片保存到磁盘?

winJS(CameraCaptureUI)如何预览(完成)并将(?)图片保存到磁盘?,camera,windows-runtime,windows-8.1,winjs,Camera,Windows Runtime,Windows 8.1,Winjs,我做了很多研究,尝试了很多不起作用的东西。 所以我需要的是: 获取图片(工作) 显示为用户预览(工作) 在图片库中创建图像(工作) 将预览作为该图像保存到本地图片文件夹(缺少) 谢谢 我捕获一张图片并将其显示在页面上,如下所示: function captureImage() { //S1: Create a new Camera Capture UI Object var cam = Windows.Media.Capture.CameraCaptureUI(); var n

我做了很多研究,尝试了很多不起作用的东西。 所以我需要的是:

  • 获取图片(工作)
  • 显示为用户预览(工作)
  • 在图片库中创建图像(工作)
  • 将预览作为该图像保存到本地图片文件夹(缺少)
  • 谢谢

    我捕获一张图片并将其显示在页面上,如下所示:

      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
    
    }
    
    函数captureImage()
    {
    //S1:创建一个新的摄影机捕获UI对象
    var cam=Windows.Media.Capture.CameraCaptureUI();
    var name=document.getElementById('ticketnum').innerHTML+'.jpg';
    var folder=Windows.Storage.KnownFolders.picturesLibrary;//是Windows.Storage
    //S2:执行异步操作,其中捕获
    //图像将作为文件存储
    cam.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo)
    .完成(功能(数据){
    如果(数据)
    {
    //S3:为捕获图像创建URL
    //并将其分配给以下是答案:

    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
    }
    
    函数testSavePictureDisk(){
    //S1:创建一个新的摄影机捕获UI对象
    var cam=Windows.Media.Capture.CameraCaptureUI();
    //地点?
    var name=document.getElementById('ticketnum').innerHTML+'.jpg';
    var folder=Windows.Storage.KnownFolders.picturesLibrary;//是Windows.Storage
    //S2:执行异步操作,其中捕获
    //图像将作为文件存储
    folder.createFileAsync(名称,
    Windows.Storage.CreationCollisionOption.replaceExisting)//是否创建新文件?
    .then(函数(文件){
    cam.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo)
    .完成(功能(数据){
    如果(数据){
    //S3:为捕获图像创建URL
    //并将其分配给
    台阶
    
  • 创建新文件
  • 捕获一张图片并预览它
  • 将图片移动到文件
  • 是的,您发现从捕获中返回的“数据”变量是一个StorageFile对象,如果查看其属性,您将看到camera capture在您的temp appdata位置创建了一个文件。因此,您可以使用其moveAsync或MoveAndResplaceAsync方法将其传输到另一个位置。