Cordova: how to take a picture without using camera app

為{幸葍}努か 提交于 2019-12-12 10:55:46

问题


I'm working on an Android App with Apache Cordova. I'd like to take a picture without opening camera application. I'd like the camera shoot by clicking a button from my app and save the picture on a specific destination with no interaction with the camera phone application.

Here the simple js I'm using to call getPicture (It produces an asynchronous call to camera application):

function capturePhoto() {
  navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
  destinationType: destinationType.DATA_URL });
}

回答1:


Solved using CameraPictureBackground plugin:

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>

You will find your pictures under CameraPictureBackground directory in your device acrhive. I used also file-transfer plugin in order to directly upload the pictures on my server over the internet.



来源:https://stackoverflow.com/questions/28295964/cordova-how-to-take-a-picture-without-using-camera-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!