I am getting this error when trying to create a Jimp object from a buffer.
The weird thing is, this works consistently when the screenshot is of the full thing but doesn't work at some croppings of the screenshot
ie. when I am inputting a screenshot of various parts of the screen at various sizes and shapes, it either works or doesn't consistently for the size/ratio
export function saveScreenshot(screenshot, fileName) {
let img = screenshot.image
let width = screenshot.width
let height = screenshot.height
let fixedImg = new Uint8Array(img.length);
for (let i=0; i < img.length; i+=4) {
fixedImg[i] = img[i+2]; // r
fixedImg[i+1] = img[i+1]; // g
fixedImg[i+2] = img[i+0]; // b
fixedImg[i+3] = 255; // a
}
new Jimp({data: fixedImg, width: width, height: height}, (err, image) => {
console.log(err)
image.resize(DETECTION_WIDTH, DETECTION_HEIGHT).write(fileName);
});
}