Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I fit a vector curve outline envelope to an offscreen bitmap?
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>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.</p> <p>Does anyone have any suggestions, solutions, pointers, or references for how to do this? Or, is there maybe another way?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThere 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?
      singulars
    2. COI'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.
      singulars
    3. COI 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.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload