-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
83 lines (77 loc) · 2.05 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
canvas {
border: 1px solid #000;
}
img{
display:block;
border: 1px solid #000;
}
.box1{
float:left;
width:400px;
height:400px;
}
.box2 {
float:right;
width:600px;
height:400px;
}
</style>
</head>
<body>
<div class='box1'>
<input type="file" id='file'><br>
<img src="" height="300" width="300" alt="" id="img"><br>
</div>
<div class='box2'>
<video src="" id='video' width='300'height='300'></video>
<canvas width="100" height="100"></canvas>
<button >拍照预览</button>
</div>
</body>
<script>
var fileObj=document.getElementById("file");
var img=document.getElementById("img");
var video=document.getElementById('video');
var button=document.getElementsByTagName('button')[0];
var canvas=document.getElementsByTagName('canvas')[0];
var cts=canvas.getContext("2d");
//上传图片预览
fileObj.onchange=function(){
var src = window.URL.createObjectURL(fileObj.files[0]);
console.log(fileObj.files);
console.log(src);
img.src=src;
}
//兼容写法
function GetUserMedia(obj,fn1,fn2){
if(navigator.getUserMedia){
return navigator.getUserMedia(obj,fn1,fn2)
}
else if(navigator.webkitGetUserMedia){
return navigator.webkitGetUserMedia(obj,fn1,fn2)
}
else if(navigator.mozGetUserMedia){
return navigator.mozGetUserMedia(obj,fn1,fn2);
}
else{
alert("don't support");
}
}
//canvas获取video图片
var p = GetUserMedia({ video: true },function(mediaStream) {
video.src = window.URL.createObjectURL(mediaStream);
video.onloadedmetadata = function(e) {
video.play();
};
},function(err){console.log(err)});
button.onclick=function(){
cts.drawImage(video,0,0,100,100);
}
</script>
</html>