paintfreeform

Implementing free form drawing in a paint app


I'd like to pick your brains on how to implement freeform drawing in a paint app. Given that the command object would encompass the click down, the arbitrarily dragging around, and the release, how would this be necessarily stored in the command and drawn onto the bitmap context?

For starters, would the data simply be every pixel coordinate reported in the mousemove command put in a large list? I can't think of any other obvious approach since the user is probably not drawing long completely straight lines that could be optimized.

Would the drawing of it be to essentially stamp solid circles (of the radius that is the pen width) at every coordinate reported in the mouse move, and interpolated in between if the move jumps far enough?

Update: Clarification on what I meant when I asked how the data would be stored. I was talking about how the data in the command object would look and figured it would be a list of 'move-to' pixel coordinates to represent the action. I wasn't referring to the representation of the data in the bitmap image that was being drawn upon.


Solution

  • I guess it depends on whether you want to have undo functionality. If not, you don't need to store the command list, you can just update the bitmap in the MouseMove handler.

    If you want to be able to undo, then you might want to store the commands (in which case a list of coordinates that the mouse moved to during drawing i.e. while the mouse button is down) is one way to do it. You would also need to keep track of the settings (e.g. pen radius, colour, etc.).

    Alternatively you could just store multiple copies of the bitmap after each command finished (although this would use a lot of memory for large bitmaps).