-
I've loaded a sketchpad trial with a background image. What I want to do now is to get the pixel value of the pixel that is being clicked.
I then adjusted the start_draw function so that it only logs the current pixel value and doesnt draw anything:
Using these adjustments, however, always gives me white pixels (i.e., [255,255,255,255]), even when I am clearly clicking on a black part of the background. What am I doing wrong here? Should I fetch the pixel array at a different time? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @HenningTm I think the this.background_image.onload = () => {
this.ctx.drawImage(this.background_image, 0, 0);
//Get pixel array
this.ctx = this.sketchpad.getContext("2d");
this.imageData = this.ctx.getImageData(0, 0, this.params.canvas_width, this.params.canvas_height);
this.pixelArray = this.imageData.data;
resolve(true);
}; The |
Beta Was this translation helpful? Give feedback.
Hi @HenningTm
I think the
pixelArray
should be updated after theonload
event finishes for the background image.The
imageData
doesn't update untilthis.ctx.drawImage
is called.