0

我有一个从浏览器打开相机的代码。如何改进此代码以便我可以将文件保存在本地目录中。

document.getElementById('takephoto').onclick = function(){
    console.log(navigator.camera);
    navigator.camera.getPicture(function(imageUri){
        var lastphoto = document.getElementById("thephoto");
        alert("nicephoto");
        lastphoto.innerHTML = "<img src='" + imageUri + "'style='width:100%;'/>"
    }, null, null);

}

使用此代码,我可以访问相机

4

1 回答 1

0

尝试使用它,看看是否有帮助

  document.getElementById('takephoto').onclick = function(){
        console.log(navigator.camera);
        navigator.camera.getPicture(function(imageUri){
            var lastphoto = document.getElementById("thephoto");
            alert("nicephoto");
            lastphoto.innerHTML = "<img src='" + imageUri + "'style='width:100%;'/>";
            var a = document.createElement("a"),
                url = URL.createObjectURL(file);
            a.href = url;
            a.download = filename;
            document.body.appendChild(a);
            a.click();
            setTimeout(function() {
             document.body.removeChild(a);
              window.URL.revokeObjectURL(url);  
            }, 0); 
            download(imageUri, "someFilename.jpg", "image");
        }, null, null);

    }
于 2018-06-21T06:51:43.043 回答