Re: Loss of precision when drawing gridlines and blocks on top.....

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



..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.
.



Relevant Pages

  • Re: An(other) BASIC bug
    ... All my versions of BBC BASIC automatically promote integers to floats ... development path to Acorn versions. ... as for POINT(with the bracket. ... So BBC BASIC for Windows uses PLOT ...
    (comp.sys.acorn.programmer)
  • Re: segmentation fault
    ... are in single column and floats) ...
    (comp.lang.python)
  • Re: Announcement: Axiom, a Forth Based Universal Game Programming System
    ... 32-bit floats in an application named xyplot, to conserve memory. ... actually have data which I cannot plot with this program, ... For example, there may be explicit casts of double numbers to float, which ... XYPLOT's built-in Forth interpreter does use double floats (two cell fp numbers ...
    (comp.lang.forth)