xxxxxxxxxx
47
const filename = 'full-width-test'
let img;
let bytearray = [];
function preload() {
img = loadImage('full-width-test.bmp')
}
function setup() {
createCanvas(img.width, img.height);
image(img,0,0)
print(img.width)
print(img.height)
img.loadPixels()
let paper = img.height*6
bytearray = [27,87,0,0,0,0,0,2,paper%256, floor(paper/256)];
for(let y=0;y<img.height;y+=8){
bytearray = bytearray.concat([ 27, 42, 0, img.width%256, floor(img.width/256) ])
for(let x = 0;x<img.width;x++){
let num=0;
for(let i=0;i<8;i++){
if(img.pixels[(y+i) *4*img.width + x*4] < 128){
num += 2**(7-i);
}
}
bytearray.push(num)
}
bytearray = bytearray.concat( [27,74,48])
}
print(bytearray)
let file = new Uint8Array(bytearray.length);
file.set(bytearray);
// save with a blob object
let blob = new Blob([file], { type: 'application/octet-stream' });
let link = createA('', filename + '.rct');
let url = URL.createObjectURL(blob);
link.attribute('href', url);
link.attribute('download', filename + '.rct');
link.elt.click();
URL.revokeObjectURL(url);
link.remove()
}