本文介绍了如何使用PhoneGap的显示Android手机上摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用Android手机上的PhoneGap捕获图像。我尝试code PhoneGap的发布页面上,但相机不会出现。任何帮助是AP preciated.Thank你了。
这是显示我的手机上
<!DOCTYPE HTML>
< HTML和GT;
< HEAD>
<标题>捕获照片< /标题> <脚本类型=文/ JavaScript的字符集=utf-8SRC =科尔多瓦-1.6.0.js>< / SCRIPT>
<脚本类型=文/ JavaScript的字符集=utf-8> VAR pictureSource; //图片来源
VAR destinationType; //设置返回值的格式 //等待科尔多瓦与设备连接
//
document.addEventListener(deviceready,onDeviceReady,FALSE); //科尔多瓦是随时可以使用!
//
功能onDeviceReady(){
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
} //如果照片是成功检索调用
//
功能onPhotoDataSuccess(为imageData){
//取消注释查看的base64 EN codeD图像数据
//执行console.log(为imageData); //获取图像句柄
//
变种smallImage =的document.getElementById('smallImage'); //取消隐藏图像元素
//
smallImage.style.display =块; //显示所拍摄的照片
//内联CSS规则是用来调整图像大小
//
smallImage.src =数据:图像/ JPEG; BASE64,+为imageData;
} //如果照片是成功检索调用
//
功能onPhotoURISuccess(imageURI){
//取消注释查看图像文件URI
//执行console.log(imageURI); //获取图像句柄
//
变种largeImage =的document.getElementById('largeImage'); //取消隐藏图像元素
//
largeImage.style.display =块; //显示所拍摄的照片
//内联CSS规则是用来调整图像大小
//
largeImage.src = imageURI;
} //一个按钮将调用这个函数
//
功能capturePhoto(){
//将图片使用设备的摄像头和图像检索为base64-CN codeD字符串
navigator.camera.getPicture(onPhotoDataSuccess,onFail,{质量:50,
destinationType.DATA_URL});
} //一个按钮将调用这个函数
//
功能capturePhotoEdit(){
//将图片使用设备的摄像头,让编辑和图像检索为base64-CN codeD字符串
navigator.camera.getPicture(onPhotoDataSuccess,onFail,{质量:20,allowEdit:真实,
destinationType.DATA_URL});
} //一个按钮将调用这个函数
//
功能getPhoto(源){
//从指定源中检索图像文件位置
navigator.camera.getPicture(onPhotoURISuccess,onFail,{质量:50,
destinationType:destinationType.FILE_URI,
sourceType的:源});
} //调用如果有什么不好的事情发生。
//
功能onFail(消息){
警报('因为失败:'+消息);
} < / SCRIPT>
< /头>
<身体GT;
<按钮的onclick =capturePhoto();>捕获照片< /按钮> < BR>
<按钮的onclick =capturePhotoEdit();>捕获编辑照片及LT; /按钮> < BR>
<按钮的onclick =getPhoto(pictureSource.PHOTOLIBRARY);肽从图片库< /按钮>< BR>
<按钮的onclick =getPhoto(pictureSource.SAVEDPHOTOALBUM);>从相册和LT; /按钮>< BR>
< IMG风格=显示:无;宽度:60像素,高度:60像素; ID =smallImageSRC =/>
< IMG风格=显示:无; ID =largeImageSRC =/>
< /身体GT;
< / HTML>
解决方案
这两个你的 capturePhoto()
和 capturePhotoEdit()
功能需要有 destinationType
更新。
navigator.camera.getPicture(
onPhotoDataSuccess,
onFail,
{
品质:50,
destinationType.DATA_URL
}
);
应该是这样的,
navigator.camera.getPicture(
onPhotoDataSuccess,
onFail,
{
品质:50,
destinationType:destinationType.DATA_URL
}
);
I want to capture an image by using phonegap on Android phone. I try the code posted on Phonegap page but the camera does not appear. Any help is appreciated.Thank you very much.
It is the display on my phone
<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.6.0.js"></script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for Cordova to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);
// Cordova is ready to be used!
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);
// Get image handle
//
var smallImage = document.getElementById('smallImage');
// Unhide image elements
//
smallImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
// console.log(imageURI);
// Get image handle
//
var largeImage = document.getElementById('largeImage');
// Unhide image elements
//
largeImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
largeImage.src = imageURI;
}
// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType.DATA_URL });
}
// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType.DATA_URL });
}
// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
</head>
<body>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
</body>
</html>
解决方案
Both your capturePhoto()
and capturePhotoEdit()
functions need to have the destinationType
updated.
navigator.camera.getPicture(
onPhotoDataSuccess,
onFail,
{
quality: 50,
destinationType.DATA_URL
}
);
should be like this,
navigator.camera.getPicture(
onPhotoDataSuccess,
onFail,
{
quality: 50,
destinationType: destinationType.DATA_URL
}
);
这篇关于如何使用PhoneGap的显示Android手机上摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!