|
我在phonegap android拍照,执行时出现不能加载getPicture
代码是:
<script type="text/javascript" charset="utf-8">
var pictureSource; //设定图片来源
var destinationType; //选择返回数据的格式
document.addEventListener("deviceready",onDeviceReady,false);
// cordova准备好了可以使用了
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function onPhotoDataSuccess(imageData) {
// base64 encoded image data
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
//在使用base64编码的时候需要使用这样的前缀
smallImage.src = "data:image/jpeg;base64," + imageData;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// image file URI
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
//使用image file URI 直接赋值就可以了
largeImage.src = imageURI;
}
// 第一个按钮调用函数
function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {quality: 50});
}
//第二个按钮调用的函数
function capturePhotoEdit() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true});
}
//第三/四个按钮调用的函数
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, destinationType: destinationType.FILE_URI, sourceType: source });
}
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
<a href="#" onclick="capturePhoto();" data-role="button" > 拍照 </a> |
|