Reputation: 39
In my aplication I need to plot an equation. The plotted equation will be composed of many small linear lines. When I plot it using the DrawLine method inside a for I get higher quality than when using the DrawLines method.
Graphics canvas = pnlCanvas.CreateGraphics();
canvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//High Quality
for (int i = 0; i < plot_points.Length - 1; i++)
{
canvas.DrawLine(penKat, plot_points[i], plot_points[i + 1]);
}
//Low Quality
canvas.DrawLines(penKat, plot_points);
I need to plot it using the DrawLines method because of some issues. Is there a way to get high quality using that method?
Upvotes: 2
Views: 780
Reputation: 54453
Try:
penKat.EndCap = System.Drawing.Drawing2D.LineCap.Round;
penKat.StartCap = System.Drawing.Drawing2D.LineCap.Round;
penKat.LineJoin = LineJoin.Round;
MiterLimit might help, if your lines are thicker than a few pixels..
Edit: For crisp joins you may want to experiment with other LineJoin values:
penKat.LineJoin = LineJoin.MiterClipped;
penKat.MiterLimit = 1.5f;
Or
penKat.LineJoin = LineJoin.Miter;
penKat.MiterLimit = 1.5f;
Do try out other MiteLimit values until you're happy! Or post an example image with the two versions..
For stroke widths of 2-4 pixels the difference between the LineJoins will not be very visible. This changes dramatically with growing stroke widths; so remember this property for those thicker lines!
Upvotes: 2