[英]Phonegp App crash using camera
I am exploring the different things that Phonegap can do one of which is taking a photograph and adding it to a page. 我正在探索Phonegap可以执行的不同操作,其中之一是拍照并将其添加到页面中。 When I test this however on my device i get as far as taking the picture then the app just crashes with a message on the phone saying "Unfortunately my app has stopped". 但是,当我在设备上对此进行测试时,我所能拍到的照片最多,然后该应用程序崩溃,并在手机上显示一条消息,提示“不幸的是我的应用程序已停止运行”。 Here is the code I am using. 这是我正在使用的代码。 I'm wondering if its anything to do with the encoding but I did take that directly from the phongap documnet page. 我想知道它是否与编码有关,但我确实直接从phongap documnet页面上获取了它。 #addphoto is a button on the html page that i wish to add the photo to. #addphoto是我希望将照片添加到html页面上的按钮。 The photo is to go inside the div with the id noteimage 这张照片要放在带有id noteimage的div内
$("#addphoto").on('click', function(){
useGetPicture();
});
function useGetPicture(){
var cameraOptions = {
quality: 75,
desinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
correctOrientation: true,
}
navigator.camera.getPicture( onCameraSuccess, onCameraError, cameraOptions);
}
function onCameraSuccess(imageData){
var image = document.getElementById("noteimage");
image.src = "data:image/jpeg;base64," + imageData;
}
function onCameraError(message){
alert("Failed: " + message);
}
Please check have you given camera permission in manifest file and reduce the quality. 请检查清单文件中是否已授予相机许可并降低质量。
This might be helpful for you... 这可能对您有帮助...
navigator.camera.getPicture(function (imageData) {
//imageData: base64 string
},
function(error){
alert('error');
},
{quality: 30,targetWidth: 640,targetHeight: 400,destinationType: Camera.DestinationType.DATA_URL}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.