Re: Loss of precision when drawing gridlines and blocks on top.....
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Feb 2008 18:37:41 +0100
..NET drawing uses floats for accuracy but must ultimately be rendered on an integer raster. The only way to ensure the accuracy is to plot the lines positioned by floats and ensure that the Graphics object selects the nearest pixel by setting the pixeloffset mode correctly.
When converting floats to integers always round to the nearest by adding 0.5f. This will make the general appearance much better.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
alexstevens@xxxxxxxxxxxxxxxx wrote:
.As for options I'm not too sure, what are you trying to do?
Michael
Michael - many thanks for your response. It may be the overall
approach to this which is wrong.
I'm trying to create a grid which has 24 hours across the top, and a
number of channels down the left. I need to firstly draw out the grid
lines to form a matrix, and then plot blocks of time on the grid to
represent programmes. How can I guarantee the accuracy of elements
that I draw? I've no problem with being unable to draw at a sub-pixel
level (as I suspected), but when I plot the location and size of two
seperate elements (the gridlines and the block on top) and then
resize, the inaccuracy is augmented.
Run up the sample code an resize it in realtime, you'll see that issue
immediately.
I couldn't find anything on codeproject which was close enough to my
needs, anything commercially available isn't worth it for a pet
project, and I thought it would be a good way to get to grips with
custom drawing.
Thanks for your help.
- References:
- Loss of precision when drawing gridlines and blocks on top.....
- From: alexstevens
- Re: Loss of precision when drawing gridlines and blocks on top.....
- From: Michael C
- Re: Loss of precision when drawing gridlines and blocks on top.....
- From: alexstevens
- Loss of precision when drawing gridlines and blocks on top.....
- Prev by Date: Re: Loss of precision when drawing gridlines and blocks on top.....
- Next by Date: Re: WPF Background issue
- Previous by thread: Re: Loss of precision when drawing gridlines and blocks on top.....
- Next by thread: Re: Loss of precision when drawing gridlines and blocks on top.....
- Index(es):
Relevant Pages
|