-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
sample_ex.html
63 lines (48 loc) · 1.91 KB
/
sample_ex.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Image Processing</title>
</head>
<body>
<h1>Image Processing!</h1>
<canvas id="canvas" style="border: solid thin black;"></canvas>
<canvas id="canvas_result" style="border: solid thin black;"></canvas>
<br>
<button onclick="process();" style="margin-left: 90px; font-size: 20px;">process!</button>
<script type="text/javascript">
let image = new Image();
var src = "imori.jpg";
image.src = src;
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const canvas_result = document.getElementById("canvas_result");
const ctx_result = canvas_result.getContext("2d");
image.onload = () => {
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
canvas_result.width = image.width;
canvas_result.height = image.height;
}
function process(){
let src = ctx.getImageData(0, 0, image.width, image.height);
let dst = ctx_result.createImageData(image.width, image.height);
//for ( var i = 0; i < 128; i++){ src.data[i * 4] = 255;}
/*
src.data[29 * 4 + 19 * 128 * 4] = 255;
src.data[29 * 4 + 19 * 128 * 4 + 1] = 0;
src.data[29 * 4 + 19 * 128 * 4 + 2] = 0;
//src.data[29 * 4 + 19 * 128 + 3] = 0;
*/
for (let i = 0; i < src.data.length; i+= 4){
dst.data[i] = src.data[i];
dst.data[i+1] = src.data[i+1];
dst.data[i+2] = src.data[i+2];
dst.data[i+3] = src.data[i+3];
}
ctx_result.putImageData(dst, 0, 0);
}
</script>
</body>
</html>