剛好在某個 maillist 看到這篇文章,可以解答您的問題
http://www.daa.com.au/pipermail/pygtk/2008-September/015991.html摘錄如下:
Jeffrey Drake wrote:
> In my code below, I set a line width of 1 and then when I go to draw a
> grid, what appears is an antialiased line of still width of 2. I need a
> single pixel, not the ugly 2 width beast as shown before.
>
> The problem is when drawing the horizontal grid below.
>
> Any ideas on how to fix this?
Add (or subtract) 0.5 to the x and y of your line endpoints.
In cairo, the top left pixel is a rectangle from (0,0) to (1,1). The
top left corner is (0,0) and the bottom right corner is (1,1). If you
have a 1-pixel wide line from (10,10) to (100,10) only half of that
1-pixel is in the 10th row, the other half being in the 9th row. Cairo
renders this by antialiasing, so you get a 2-pixel side 50% gray line
rather than the 1-pixel black line you were expecting.
--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/