Search code examples
c#imagepicturebox

Making scribbles on a monochrome image


Imagine there's a picturebox which loads a monochrome image. And there is a need to make few color scribbles on it. I have no background with graphics. Would it be just a pen drawing pixels or something more complex I don't know.

Target language is C#. Technology: WinForms.


Solution

  • I think the easiest way to achieve what you want would be to create a very lightweight retained mode drawing system. Keep track of all the positions where the user has scribbeled and draw dots/circles/lines/rubberducks/whatever at these positions in the PictureBox's Paint event. On mousedown+move events, call the PictureBox' Invalidate() function. The original picture must either be painted underneath or in the class' OnPaintBackground (which IMO is more elegant).

    This tutorial should get you started:

    https://web.archive.org/web/20121006140255/http://www.bobpowell.net/backtrack.htm