@@ -3,3 +3,48 @@ const canvas = document.querySelector('.photo');
33const ctx = canvas . getContext ( '2d' ) ;
44const strip = document . querySelector ( '.strip' ) ;
55const snap = document . querySelector ( '.snap' ) ;
6+
7+
8+ function getVideo ( ) {
9+ navigator . mediaDevices . getUserMedia ( {
10+ video : true ,
11+ audio : false
12+ } )
13+ . then ( localmediastream => {
14+ console . log ( localmediastream ) ;
15+ video . src = window . URL . createObjectURL ( localmediastream ) ;
16+ video . play ( ) ;
17+ } )
18+ . catch ( err => console . error ( err ) ) ;
19+ }
20+
21+
22+ function paintToCanvas ( ) {
23+ const width = video . videoWidth ;
24+ const height = video . videoHeight ;
25+ canvas . width = width ;
26+ canvas . height = height ;
27+
28+ return setInterval ( ( ) => {
29+ ctx . drawImage ( video , 0 , 0 , width , height ) ;
30+ let pixels = ctx . getImageData ( 0 , 0 , width , height ) ;
31+ console . log ( pixels ) ;
32+ debugger ;
33+ } , 16 ) ;
34+ }
35+
36+ function takePhoto ( ) {
37+ snap . currentTime = 0 ;
38+ snap . play ( ) ;
39+ const data = canvas . toDataURL ( 'image/jpeg' ) ;
40+
41+ const link = document . createElement ( 'a' ) ;
42+ link . href = data ;
43+ link . setAttribute ( 'download' , 'handsome' ) ;
44+ link . innerHTML = `<img src="${ data } " alt="person"/>` ;
45+ strip . insertBefore ( link , strip . firstChild ) ;
46+
47+ }
48+
49+ getVideo ( ) ;
50+ video . addEventListener ( 'canplay' , paintToCanvas ) ;
0 commit comments