wPaint icon indicating copy to clipboard operation
wPaint copied to clipboard

To Know if canvas is empty

Open dsicom opened this issue 10 years ago • 2 comments

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

dsicom avatar Apr 24 '15 13:04 dsicom

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.

abrenoch avatar Oct 02 '15 14:10 abrenoch

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) {

rb1515 avatar Nov 05 '15 18:11 rb1515