Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

To Know if canvas is empty #106

Open
dsicom opened this issue Apr 24, 2015 · 2 comments
Open

To Know if canvas is empty #106

dsicom opened this issue Apr 24, 2015 · 2 comments

Comments

@dsicom
Copy link

dsicom commented Apr 24, 2015

I need to force at the user to paint something in wPaint. Are there any manner to check if the canvas is empty or not?
Thanks

@abrenoch
Copy link

abrenoch commented Oct 2, 2015

Check out:
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData

This will return an array of all the pixels in rgba value, you could potentially loop over every integer in that array and if they all are 0 then it would be reasonable to assume the canvas is blank.

@rb1515
Copy link

rb1515 commented Nov 5, 2015

I store the empty canvas on init and later compare the current sta with the empty one:

// on init
emptyImage = wPaintCanvas.toDataURL();
// later
if(wPaintCanvas.toDataURL() === emptyImage) {

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@dsicom @abrenoch @rb1515 and others