我正在显示一个使用 phonegap 打开相机的按钮:
document.addEventListener("deviceready", loaded, false);
function loaded() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
function capturePhoto() {
navigator.camera.getPicture(getPhoto, onFail, {
quality : 50
});
}
function getPhoto(imageData) {
alert(imageData);
var smallImage = document.getElementById('cameraPic');
smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
<body>
<div id="camera">
<button class="camera-control" onclick="capturePhoto();">CapturePhoto</button>
<div style="text-align: center; margin: 20px;">
<img id="cameraPic" src="" style="width: auto; height: 120px;"> <img>
</div></div>
</body>
单击按钮时,我想解码 QR 码并在我的页面上显示解码后的值。我只想使用 javascript 和 phonegap 来执行此操作,并且不想使用任何本机代码。