SmoothingMode distorts the Dashed Pen
Why is enabling anti-aliasing interfering with my dotted pen?
alt text http://agnel.kurian.googlepages.com/antialiased_dashes.PNG
+1
a source to share
1 answer
I believe this is a problem with creating a pen with a width of 0 and scaling. As I see it, there are two ways around this:
- Create a handle with a larger width. I found that at 0.38f the dash in the antialiased line started to scale correctly.
- Manually convert the values to the Pen DashPattern property.
You can use the latest workaround with a bit of C # 3.0 code:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
using (Pen p = new Pen(Color.Black, 0.0f))
{
p.DashStyle = DashStyle.Dash;
g.ScaleTransform(4.0f, 4.0f);
g.DrawLine(p, 5.0f, 5.0f, 55.0f, 5.0f);
g.SmoothingMode = SmoothingMode.AntiAlias;
p.DashPattern = Array.ConvertAll(p.DashPattern, d => d * 4.0f);
g.DrawLine(p, 5.0f, 10.0f, 55.0f, 10.0f);
}
base.OnPaint(e);
}
+4
a source to share