-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.html
53 lines (47 loc) · 2.06 KB
/
canvas.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>capture screen</title>
</head>
<body>
<video id="video" controls="controls" crossorigin="anonymous">
<source src="http://apptest.mhc.mobile.taikang.com/publish/storage/fileGet?fileId=ff808181631f84470163200737bd001b">
</video>
<div id="output"></div>
<button onclick="jietu()">截图</button>
<script type="text/javascript">
(function() {
var video, output;
var scale = 0.8;
var initialize = function() {
output = document.getElementById("output");
video = document.getElementById("video");
// video.addEventListener('loadeddata', captureImage);
};
// var captureImage = function() {
// var canvas = document.createElement("canvas");
// canvas.width = video.videoWidth * scale;
// canvas.height = video.videoHeight * scale;
// canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
//
// var img = document.createElement("img");
// img.src = canvas.toDataURL("image/png");
//// output.appendChild(img);
// };
initialize();
})();
function jietu(){
var scale = 0.4;
var canvas = document.createElement("canvas");
canvas.width = video.videoWidth * scale;
canvas.height = video.videoHeight * scale;
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
var img = document.createElement("img");
img.src = canvas.toDataURL("image/png");
console.log(img.src)
output.appendChild(img);
}
</script>
</body>
</html>