How do I fit a vector curve outline envelope to an offscreen bitmap?

290 Views Asked by At

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?

0

There are 0 best solutions below