Created
February 13, 2020 08:37
-
-
Save stengoes/e17781a920ba75c72eacf981360dbfcf to your computer and use it in GitHub Desktop.
Example using html5 canvas tags to display rgb arrays.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<canvas id="mycanvas" width="2048" height="512"></canvas> | |
</body> | |
</html> | |
<script> | |
const height = 512; | |
const width = 256; | |
const depth = 4; | |
const data = new Uint8ClampedArray(height*width*depth); | |
// Fill data | |
for (let i = 0; i < data.length; i += 4) | |
{ | |
data[i + 0] = 255; // R value | |
data[i + 1] = 0; // G value | |
data[i + 2] = 0; // B value | |
data[i + 3] = 255; // A value | |
} | |
const imgData = new ImageData(data, width, height); | |
const canvas = document.getElementById('mycanvas'); | |
const ctx = canvas.getContext('2d'); | |
ctx.putImageData(imgData, 0, 0); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment