javascript: webcam
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="geovindu,Geovin Du,涂聚文">
<meta name="author" content="geovindu,Geovin Du,涂聚文">
<title>webcam</title>
<script src="js/modernizr.custom.82437.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5-els.js"></script>
<![endif]-->
</head>
<body>
<div id="screenshot" style="text-align:center;">
<video class="videostream" autoplay></video>
<img id="screenshot-img">
<p><button class="capture-button">Capture video</button>
<p><button id="screenshot-button" disabled>Take screenshot</button></p>
<canvas style="display:none;"></canvas>
</div>
<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="bootstrap/4.4.1/js/bootstrap.bundle.min.js" ></script>
<script type="text/javascript">
function handleError(error) {
console.error('navigator.getUserMedia error: ', error);
}
const constraints = {video: true};
const captureVideoButton = document.querySelector(
"#screenshot .capture-button"
);
const screenshotButton = document.querySelector("#screenshot-button");
const img = document.querySelector("#screenshot img");
const video = document.querySelector("#screenshot video");
const canvas = document.createElement("canvas");
captureVideoButton.onclick = function () {
navigator.mediaDevices
.getUserMedia(constraints)
.then(handleSuccess)
.catch(handleError);
};
screenshotButton.onclick = video.onclick = function () {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext("2d").drawImage(video, 0, 0);
// Other browsers will fall back to image/png
img.src = canvas.toDataURL("image/webp");
};
function handleSuccess(stream) {
screenshotButton.disabled = false;
video.srcObject = stream;
}
</script>
</body>
</html>
from: https://www.html5rocks.com/en/tutorials/getusermedia/intro/
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
浙公网安备 33010602011771号