当前位置:网站首页>JS call camera
JS call camera
2022-07-06 16:02:00 【Star age Cao Botao】
<!doctype html>
<html lang="en">
<head>
<title>GET VIDEO</title>
<meta charset="utf-8">
</head>
<body>
<input type="button" title=" Turn on camera " value=" Turn on camera " onclick="getMedia()" />
<video id="video" width="500px" height="500px" autoplay="autoplay"></video>
<canvas id="canvas" width="500px" height="500px"></canvas>
<button id="snap" onclick="takePhoto()"> Taking pictures </button>
<script> // get video Camera area let video = document.getElementById("video"); function getMedia() {
let constraints = {
video: {
width: 500, height: 500}, audio: true }; /* Here's a new way :H5 New media interface navigator.mediaDevices.getUserMedia() This method will prompt the user whether to allow media input ,( Media input mainly includes camera , Video capture devices , Screen sharing service , Microphone ,A/D Converter, etc ) Back to a Promise object . If the user agrees to use the permission , Will be MediaStream Object as resolve() The parameters of are passed to then() If the user denies permission , Or the requested media resource is not available , Will be PermissionDeniedError As reject() The parameters of are passed to catch() */ let promise = navigator.mediaDevices.getUserMedia(constraints); promise.then(function (MediaStream) {
video.srcObject = MediaStream; video.play(); }).catch(function (PermissionDeniedError) {
console.log(PermissionDeniedError); }) } function takePhoto() {
// get Canvas object let canvas = document.getElementById("canvas"); let ctx = canvas.getContext('2d'); ctx.drawImage(video, 0, 0, 500, 500); } </script>
</body>
</html>
边栏推荐
- Cost accounting [22]
- Penetration test (7) -- vulnerability scanning tool Nessus
- Research Report on market supply and demand and strategy of China's land incineration plant industry
- C语言数组的概念
- Research Report on market supply and demand and strategy of China's earth drilling industry
- 【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
- 【练习-7】(Uva 10976)Fractions Again?!(分数拆分)
- Optimization method of path problem before dynamic planning
- 基于web的照片数码冲印网站
- Accounting regulations and professional ethics [1]
猜你喜欢
随机推荐
渗透测试 ( 4 ) --- Meterpreter 命令详解
Record of brushing questions with force deduction -- complete knapsack problem (I)
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
0-1背包問題(一)
Market trend report, technical innovation and market forecast of lip care products in China and Indonesia
Research Report on market supply and demand and strategy of China's earth drilling industry
用C语言写网页游戏
TCP的三次握手与四次挥手
洛谷P1102 A-B数对(二分,map,双指针)
【练习4-1】Cake Distribution(分配蛋糕)
【练习-6】(PTA)分而治之
Opencv learning log 19 skin grinding
China's peripheral catheter market trend report, technological innovation and market forecast
China potato slicer market trend report, technical dynamic innovation and market forecast
Record of force deduction and question brushing
Opencv learning log 13 corrosion, expansion, opening and closing operations
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
PySide6 信号、槽
[exercise -10] unread messages




![[exercise-5] (UVA 839) not so mobile (balance)](/img/8e/48dcf75f7347b36301df6fc129c09d.png)



