android - Cordova:如何在不使用相机应用程序的情况下拍照

标签 android cordova camera image-capture

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

关于android - Cordova:如何在不使用相机应用程序的情况下拍照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28295964/

相关文章:

java - Kotlin 需要 ViewHolder getter/setter 中的对象

ios - Safari : no Inspectable applications

ios - ionic3 ios13 InApp浏览器崩溃

ios - 以编程方式在 iOS 中录制视频

java.lang.OutOfMemoryError 与 ArrayList.addAll()

android - 使用改造缓存特定响应

android - getActionBar() == null 什么时候不应该

cordova - "ionic build"和 "ionic prepare"之间有什么区别?

android - 将 LED 转为 TORCH 模式会出现什么错误?

linux - 零拷贝 UDP 打包是否可能在 Linux 上接收?