gpt4 book ai didi

javascript - 使用 navigator.camera 或纯 javascript 拍摄照片

转载 作者:行者123 更新时间:2023-11-30 05:39:52 24 4
gpt4 key购买 nike

我想用设备相机拍一张照片,它会被存储在某种类型的缩略图中:

function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}

function onPhotoDataSuccessFront(imageData) {

var smallImageFront = document.getElementById('smallImageFront');
smallImageFront.style.display = 'block';
smallImageFront.src = "data:image/jpeg;base64," + imageData;

$('#btnFrontDiv').text('Retake Front');
}

如您所见,我使用了 navigator.camera,它在 cordova/phonegap 中可用。我想使用 cordova 或纯 javascript 来拍摄照片。感谢您的任何建议。

最佳答案

试试这个

<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title> Cmaer</title>
<script type="text/javascript" src="cordova.js" ></script>
<script type="text/javascript">
var pictureSource,destinationType;
document.addEventListener("deviceready",loaded,false);
function loaded() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function getPhoto(imageData) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = imageData;
}
function capturePhoto() {
navigator.camera.getPicture(getPhoto, onFail, { quality: 50 });
}
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
</head>
<body>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />

</body>
</html>

Reference

关于javascript - 使用 navigator.camera 或纯 javascript 拍摄照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21457685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com