我正在使用 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/