websanova / wPaint

jQuery Paint Plugin
http://wpaint.websanova.com
351 stars 128 forks source link

To Know if canvas is empty #106

Open dsicom opened 9 years ago

dsicom commented 9 years ago

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 commented 8 years ago

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 commented 8 years ago

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