当前位置:网站首页>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>
边栏推荐
- PySide6 信号、槽
- Cost accounting [15]
- frida hook so层、protobuf 数据解析
- Common configuration files of SSM framework
- Opencv learning log 18 Canny operator
- [exercise-4] (UVA 11988) broken keyboard = = (linked list)
- Opencv learning log 13 corrosion, expansion, opening and closing operations
- 差分(一维,二维,三维) 蓝桥杯三体攻击
- b站 实时弹幕和历史弹幕 Protobuf 格式解析
- [exercise-2] (UVA 712) s-trees
猜你喜欢
TCP的三次握手与四次挥手
程序员的你,有哪些炫技的代码写法?
动态规划前路径问题优化方式
Information security - threat detection engine - common rule engine base performance comparison
Gartner:关于零信任网络访问最佳实践的五个建议
Penetration test (7) -- vulnerability scanning tool Nessus
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
Ball Dropping
洛谷P1102 A-B数对(二分,map,双指针)
Penetration test (1) -- necessary tools, navigation
随机推荐
Nodejs crawler
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
Opencv learning log 31 -- background difference
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
Gartner: five suggestions on best practices for zero trust network access
通俗地理解什么是编程语言
[exercise-7] (UVA 10976) fractions again?! (fraction split)
Opencv learning log 19 skin grinding
VS2019初步使用
[exercise-3] (UVA 442) matrix chain multiplication
Web based photo digital printing website
Penetration test (7) -- vulnerability scanning tool Nessus
C 基本语法
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
[exercise-2] (UVA 712) s-trees
【练习4-1】Cake Distribution(分配蛋糕)
TCP的三次握手与四次挥手
对iptables进行常规操作
STM32 how to use stlink download program: light LED running light (Library version)