【问题标题】:Cordova: how to take a picture without using camera appCordova:如何在不使用相机应用程序的情况下拍照
【发布时间】:2015-04-02 11:23:44
【问题描述】:

我正在使用 Apache Cordova 开发 Android 应用程序。我想在不打开相机应用程序的情况下拍照。 我希望通过单击我的应用程序中的按钮来进行相机拍摄,并将照片保存到特定的目的地,而无需与照相手机应用程序进行交互。

这里是我用来调用 getPicture 的简单 js(它产生对相机应用程序的异步调用):

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

【问题讨论】:

    标签: android cordova camera image-capture


    【解决方案1】:

    使用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 目录下找到您的图片。我还使用了文件传输插件,以便通过互联网直接将图片上传到我的服务器上。

    【讨论】:

    • 我猜这不适用于 Android 7.. 是否可以替代 Android 7?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    • 2014-12-10
    相关资源
    最近更新 更多