-
Notifications
You must be signed in to change notification settings - Fork 85
/
ScalingImage.html
65 lines (59 loc) · 1.59 KB
/
ScalingImage.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
<!DOCTYPE html>
<!--
Author:苏一恒
Date:2019/10/29 20:15
Motto:
The best time to plant trees is ten years ago, followed by now.
种树最好的时间是十年前,其次是现在。
-->
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>图像的绘制</title>
<style>
body {
background: #eeeeee;
}
#canvas {
background: #ffffff;
margin-top: 5px;
margin-left: 10px;
-webkit-box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
border: 1px solid rgba(0, 0, 0, 0.2);
}
</style>
</head>
<body>
<div id='controls'>
<input id='scaleCheckbox' type='checkbox'/>
缩放图片
</div>
<canvas id='canvas' height="400" width="600">canvas not supports</canvas>
<script>
'use strict';
let canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
image = new Image(),
scaleCheckbox = document.getElementById('scaleCheckbox');
let drawImage = ()=>{
context.clearRect(0,0,canvas.width,canvas.height);
if (scaleCheckbox.checked){
context.drawImage(image,0,0,canvas.width,canvas.height);
}
else{
context.drawImage(image, 0, 0);
}
context.restore();
};
scaleCheckbox.onchange=e=>{
drawImage();
};
image.src='../images/waterfall.png';
image.onload = () => {
context.drawImage(image,0,0);
};
</script>
</body>
</html>