科尔多瓦:如何拍摄照片时不使用相机应用 [英] Cordova: how to take a picture without using camera app
问题描述
我工作的一个Android应用程序与Apache科尔多瓦。我想拍摄照片,而无需打开摄像头应用程序。
我想相机拍摄从我的应用程序点击一个按钮,将图片保存在一个特定的目的地,与摄像头的手机应用程序进行交互。
下面我用打电话Getpicture中简单的JS(它产生于相机应用程序的异步调用):
函数capturePhoto(){
navigator.camera.getPicture(onPhotoDataSuccess,onFail,{质量:50,
destinationType:destinationType.DATA_URL});
}
使用 CameraPictureBackground 插件:
函数成功(imgUrl的){
的console.log(imgUrl的=+ imgUrl的);
//这里我将我的功能上传的图片保存
//使用文件转院插件我的互联网服务器上
}功能onFail(消息){
警报('因为失败:'+消息);
}功能CaptureBCK(){
VAR的选择= {
名称:图像,//图像后缀
目录名称:CameraPictureBackground,//文件夹名
方向:纵向,//或景观
类型:后退//或前
}; window.plugins.CameraPictureBackground.takePicture(成功,onFail,期权);
}
<按钮的onclick =CaptureBCK();>捕获照片< /按钮> < BR>
您会发现CameraPictureBackground目录下你的照片在你的设备acrhive。我用同样的文件传输的插件,以便直接上传的图片我的服务器在互联网上。
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 });
}
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.
这篇关于科尔多瓦:如何拍摄照片时不使用相机应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!