January 11th, 2012, 07:37 AM
[C#] Problem when drawing a line using GDI+
I have a problem drawing a line in C# using GDI+.
Please take a look at the following image
Image of the problem
As you can see from the image the second line drawn with Line thickness 2 appears straight, but it is not (look at the code down)
Every line is drawn in a way that lower X coordinate is 1px larger then top X.
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black, 1);
g.DrawLine(p, 50, 50, 51, 150);
p = new Pen(Color.Black, 2);
g.DrawLine(p, 60, 50, 61, 150);
p = new Pen(Color.Black, 3);
g.DrawLine(p, 70, 50, 71, 150);
The same thing is happening to every line with even thickness (2px, 4px, 6px, ...)
But in a program that I'm creating the line with event thickness must appear exactly the same as those with odd thickness.
The same is happening for horizontal and vertical lines with 1px difference.
Smoothness is set to none.
Please, if anybody knows the solution to this problem, please tell me. This is very urgent for me.
Thanks in advance!
January 19th, 2012, 07:09 AM
If you'd thought about this for a few minutes you'd have got it I'm quite sure... If you draw a straight line which is two pixels thick, and then draw a 1-pixel-thick line on top of it starting top left and finishing bottom right you will not be able to see it...
That one pixel difference within the computers's memory is less than the thickness of the line itself and therefore fits within it and is not represented visually.
Originally Posted by boskoc