MozTW 討論區 https://forum.moztw.org/ |
|
请教cairo的问题 https://forum.moztw.org/viewtopic.php?f=18&t=28023 |
第 1 頁 (共 1 頁) |
發表人: | zlc [ 2009-09-19, 02:27 ] |
文章主題 : | 请教cairo的问题 |
有个问题困扰我很久, 用cario画线怎样能画出只用一个像素的水平线或垂直线?我设置cairo_line_width为1也没用,我只是想画一条纯粹的线,比如(0, 0) - (300, 0) 我发现画出来的水平线高度始终最也要占用两个像素 |
發表人: | cwchien [ 2009-09-30, 23:21 ] |
文章主題 : | Re: 请教cairo的问题 |
剛好在某個 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/ |
第 1 頁 (共 1 頁) | 所有顯示的時間為 UTC + 8 小時 |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |