Hello Anders,
I reproduced your problem in the VG.net designer. When you add smoothing,
the 0-width lines no longer scale the dash pattern according to the current
transformation. So when you zoom in or out, the pattern remains the same,
when it should get larger or smaller.
One way to fix it, and make the thin line consistent with the thick one, is
to set the line width to 1. But now, the line becomes thicker as you zoom
in.
You can do a double compensation: for the 1 pixel line, set the line width
equal to the inverse of your current scaling. This will guarantee a one
pixel line. Now multiply all the custom dash pattern values by the current
scaling, to compensate for the width change. In your example, at a scale of
4 in x and y dimensions,
- line width set to .25
- dash pattern set to 20, 40, 4, 4
Now the smoothed line looks like the non-smoothed one: 1 pixel wide, with
the same dash pattern.
The VG.net designer makes it easy to experiment with GDI+ this way without
writing code.
Regards,
Frank Hileman
check out VG.net:
www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor
Anders Forsgren said:
The dash patterns scale with the Pen width, which is explained for example here:
http://msdn.microsoft.com/library/d...awlinesandshapes/drawingacustomdashedline.asp
The fact that the dash pattern (in screen space) also scales with scale transform is natural.
I'll try to produce some code/screenshots and send to your microsoft email address.
To reproduce the behavior I'm describing do the following:
-Get a graphics object to draw on (normal smoothing mode)
-Change the scale transform of the graphics to something other than 1.0
-Create a custom dash pattern
-Create a pen with this dash pattern and a solid color, pen width=1
-Draw a line on the graphics surface using the pen
-Create another pen with a width of 5, and the same dash pattern with all
elements divided by 5, i.e. {5, 10, 1} is now {1, 2, 0.2}.
What you will see now is the correct behavior, The two lines, one thin and
one thick have the same dash lengths, since we corrected for the line width.
So far so good.
To reproduce the odd behavior:
-Repeat the above steps with a non-solid color (i.e. alpha value of e.g.
128), or using a graphics object with smoothing enabled. The 2 lines will
now have different dash lengths (the compensation for pen width will not
work now, it seems one must also compensate for alpha and antialias
somehow).