-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-imagedata.html
41 lines (38 loc) · 1.26 KB
/
test-imagedata.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>ImageData Test</title>
</head>
<body>
<script src="js/bootstrap.bundle.js"></script>
<script src="js/loader.js"></script>
Example to show the creating an image in a ImageData buffer<br>
<canvas id="myCanvas" width="640" height="480" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
let imgData = ctx.createImageData(640, 480);
preloadImages(preImages);
let i;
for (i = 0; i < imgData.data.length; i += 4) {
imgData.data[i + 0] = i % 2 === 0 ? Math.random() * 200 : 255;
imgData.data[i + 1] = i % 2 === 0 ? 0 : 255;
imgData.data[i + 2] = i % 2 === 0 ? Math.random() * 100 : 255;
imgData.data[i + 3] = 255;
}
preloadImages(preImages);
ctx.putImageData(imgData, 0, 0);
c.addEventListener('click', function () {
let nImage = preImages.get("assets/images/dsectorTitle.jpg");
nImage.style.display = "none";
document.body.appendChild(nImage);
// nImage.width = 640;
// nImage.height = 480;
ctx = c.getContext("2d");
ctx.drawImage(nImage, 0, 0);
});
</script>
</body>
</html>