Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript take picture from camera

const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const snap = document.getElementById('snap'); //Button
const constraints = {
  audio: false,
  video: {
    width: {
      // min: 1024,
      ideal: canvas.width,
      // max: 1920,
    },
    height: {
      // min: 576,
      ideal: canvas.height,
      // max: 1080,
    },
  }
}

async function startWebCam() {
  try {
    //getUserMedia() returns Promise
    const stream = await navigator.mediaDevices.getUserMedia(constraints);
    video.srcObject = stream;
    window.stream = stream;
  }
  catch (e) {
    console.log(e.toString());
  }
}

var context = canvas.getContext('2d');

snap.addEventListener('click', () => {
  context.drawImage(video, 0, 0, canvas.width, canvas.height);
});

startWebCam();
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to write a program that shows a random number between 1 and 100 in your browser 
Javascript :: hashset in javascript 
Javascript :: jquery get element tag 
Javascript :: process.argv 
Javascript :: convert inches to feet javascript 
Javascript :: document.queryselector null check 
Javascript :: wordpress ajax trigger code 
Javascript :: js mouse move activate 
Javascript :: NODEJS ES6 STRING TO BASE64 
Javascript :: javascript newline to brake 
Javascript :: react native toast message 
Javascript :: Get element id by name 
Javascript :: js array get index 
Javascript :: vue loop 
Javascript :: innertext of input js 
Javascript :: javascript array findindex 
Javascript :: array javascript django 
Javascript :: unshift method in javascript 
Javascript :: count object in array javascript 
Javascript :: javascript style inline react 
Javascript :: how to convert a string to react element in javascript 
Javascript :: node-fetch 
Javascript :: get methods on an js object 
Javascript :: golang json omitempty struct 
Javascript :: how to disable link in react 
Javascript :: jquery: get selected option of the drop down list 
Javascript :: JS iterate over an array 
Javascript :: how to initialize empty javascript object 
Javascript :: what does getattribute return null for data-* attributes 
Javascript :: js get all arguments from function 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =