Skip to content

Accessing the pixel array of a sketchpad trial with background image #3243

Answered by jodeleeuw
HenningTm asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @HenningTm

I think the pixelArray should be updated after the onload event finishes for the background image.

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 imageData doesn't update until this.ctx.drawImage is called.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@HenningTm
Comment options

Answer selected by HenningTm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants