I cannot understand the way GDI+ is drawing line on a surface, may be it has some algorithm to do it.
For ex. lets take a surface 10×10 px.
Bitmap img = new Bitmap(10, 10);
Now lets draw a line on this surface, with width 5px and top offset 5px.
using (var g = Graphics.FromImage(img))
{
g.Clear(Color.White);
var pen = new Pen(Color.Brown);
pen.Width = 5;
g.DrawLine(pen, 0F, 5F, 10F, 5F);
}
We will get:

The drawing didn’t begin at pixel #5, it began from pixel #4.
It is obvious, that the start point is calculated separately. But how?
I’ve tried to get a regularity, and got this:
y = offset + width/2 - 1
where y is real start point y, offset is selected start point y.
But in some cases this doesn’t work. For example, lets take width=6, selected top offset = 0, we will get y=2, and it will be drawn this way:

It must show 6 pixels but it didn’t.
So there must be more general algorythm for selecting the start point, but I really have no idea aboit what it can be.
Any help appreciated.
There is no
offsetin the line drawing. The co-ordinates you specify in theDrawLinemethod define the centre of the line. The top pixel isy - width / 2and the bottom isy - width / 2 + width - 1. That second formula takes into account the fact thatwidth / 2is rounded down. Also, the top line isy = 0and the bottom line isy = 9. So, for you first line:and the second line:
The top edge is clipped to the edge of the bitmap so the line width is reduced.