【问题标题】:how to open the camera from browser and save the image in local directory for Cordova如何从浏览器打开相机并将图像保存在 Cordova 的本地目录中
【发布时间】:2018-11-30 00:48:21
【问题描述】:
我有一个从浏览器打开相机的代码。如何改进此代码以便我可以将文件保存在本地目录中。
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);
}
使用此代码我可以访问相机
【问题讨论】:
标签:
jquery
cordova
cordova-plugin-camera
【解决方案1】:
尝试使用它,看看是否有帮助
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);
}