ciz*_*974 5 camera android image-capture cordova
我正在使用Apache Cordova开发Android应用程序.我想在不打开相机应用的情况下拍照.我想通过点击我的应用程序中的按钮来拍摄相机并将照片保存在特定目的地,而不与相机手机应用程序进行交互.
这里是我用来调用getPicture的简单js(它产生对相机应用程序的异步调用):
function capturePhoto() {
  navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
  destinationType: destinationType.DATA_URL });
}
使用CameraPictureBackground插件解决:
function success(imgurl) {
  console.log("Imgurl = " + imgurl);
  //here I added my function to upload the saved pictures
  //on my internet server using file-tranfer plugin
}
function onFail(message) {
    alert('Failed because: ' + message);
}
function CaptureBCK() {
    var options = {
    name: "Image", //image suffix
    dirName: "CameraPictureBackground", //foldername
    orientation: "portrait", //or landscape
    type: "back" //or front
    };
    window.plugins.CameraPictureBackground.takePicture(success, onFail, options);
}
    <button onclick="CaptureBCK();">Capture Photo</button> <br>
您将在设备档案中的 CameraPictureBackground 目录下找到您的图片。我还使用文件传输插件,以便通过互联网直接将图片上传到我的服务器上。