javascripthtmlcanvas

How to check if something is drawn on canvas


How do I check if there is data or something drawn on a canvas?

I have this <canvas id="my-canvas"></canvas> element, and I want to check if my canvas has something drawn on it.


Solution

  • Instead of checking every single pixel, it may be much more efficient to merely record every time the canvas gets filled or stroked.

    Once a fill or stroke or has happened, then you know that something has been drawn.

    Of course 'how' is very application specific, since we don't know how your canvas is getting drawn on in the first place.