Closed wil2106 closed 1 year ago
may I know how did u solve this?
may I know how did u solve this?
There are 2 issues causing that and they both from await context.getImageData()
:
canvasImage.width / 3 * canvasImage.height / 3
Your issue might be because of the (2). So I think you can do a workaround by replacing:
const length = Object.keys(imgData.data).length;
let data = Object.values(imgData.data);
//...
const newImgData = new ImageData(canvasRef.current, data, canvasImage.height, canvasImage.width);
With:
const width = Math.floor(canvasImage.width - 1) * 3;
const height = Math.floor(canvasImage.height - 1) * 3
const length = 4 * width * height;
let data = Array.from({length}).map(_ => 0);
//...
const newImgData = new ImageData(canvasRef.current, data, width, height);
Hi,
This code should set all pixels of the picture black but only a small rectangle is set, what am I doing wrong ?
The result: