1

I am writing a drawing program that is vector-based but should have drawing tools that behave more like raster-based tools. For example - when you draw with a graphics tablet pen, the resultant vector stroke, with pressure differences and all, is actually a fill. The vector curve just fits to the outside of the stroke. Also, if you pick up the eraser and erase part of this stroke, it only erases exactly where you erase at. It does not just delete vector points, but creates new ones where it has to. These pen and eraser strokes will also be of any geometry - with not only outlines on the outside, but also holes in the middle.

I puzzled for a long time over how to do this, and last night I got the idea of drawing the pen input to an offscreen bitmap (where each pixel is one bit - either touched or untouched by the pen stroke) and then when the stroke ends (pen is lifted up) the program vectorizes this bitmap, and then either places down the vector fill with appropriate color, or performs a boolean operation with the vectors underneath in order to erase.

I can make this work with raster drawing tools (so that you're not constantly drawing lines right on the visible surface, which doesn't look good if you're drawing with transparency), but I don't know how I would fit a vector curve to this one-bit bitmap. The operation has to be fast but not real-time, as it is done once after the pen is lifted up. It also has to create optimized geometry so that only the minimum number of bezier curve points needed to describe the geometry are used.

Does anyone have any suggestions, solutions, pointers, or references for how to do this? Or, is there maybe another way?

OurManFlint
  • 79
  • 2
  • 9
  • There is another approach that could be taken. Instead of drawing to an off-screen bitmap with raster operations like Graphics.FillEllipse() and Graphics.DrawLine(), I could just get the stylus or mouse data and continuously draw vector ellipses and rectangles while the stroke is being performed. Then I could Boolean union all these shapes. I would think that the resultant vector would be fairly complex, so how would I be able to simplify a vector path programmatically? – OurManFlint Mar 12 '13 at 16:23
  • I'd avoid bitmaps. What language are you using? In Java, an [Area](http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Area.html) can combine shapes (difference, union, …) and a [Stroke](http://docs.oracle.com/javase/7/docs/api/java/awt/Stroke.html) can turn a line into an outline. Other languages might have similar tools. You can also have a look at [these](http://stackoverflow.com/q/408457) [questions](http://stackoverflow.com/q/4148831) for offset curves or [these](http://stackoverflow.com/q/8261808) [questions](http://stackoverflow.com/q/10558299) on polyline simplification. – MvG Mar 12 '13 at 21:23
  • I am using C#. I started in WinForms using GDI+ but am now moving over to WPF. If performance becomes an issue I will try to implement SlimDX, though that's a headache in itself. I am trying to understand this problem in conceptual terms, though, so I could accomplish the same thing in any app development environment. I have my eye on Qt, too. – OurManFlint Mar 12 '13 at 22:13
  • Thank you for the links. They are a good help. – OurManFlint Mar 12 '13 at 22:34

0 Answers0