I am trying to paint bits on canvas, the following way
function drawOnCanvas(hex){
const ctx = canvas.getContext("2d");
canvas.height = (30/256) * canvas.width;
ctx.fillStyle = 'black';
const portion_width = canvas.width / 256;
const portion_height = canvas.height / 30;
const bytes = hexToBytes(hex);
let x = 0, y = 0;
for(let byte of bytes) {
for(let i = 0 ; i < 8 ; i++) {
if(byte & (1 << i)) {
ctx.fillRect(x, y, portion_width, portion_height);
}
x += portion_width;
if(x >= canvas.width) {
x = 0;
y += portion_height;
}
}
}
}
Here is the html secetion
<canvas bind:this={canvas}></canvas>
<style>
canvas {
border: 2px solid red;
width:100%;
}
</style>
Here is the result
This is the same bytes decoded into image in python.
I am trying to remove but with no succsess the squares in the background, any help will be appericiated. The Applicaiton is written in svelte, But I don't think its have anything to do with my problem.

