GDI+ and Integers

1/15/2004 1:25:07 AM

GDI+ and Integers

I have been studying the implementation of GDI+ in .NET. It appears that both the C++ and C# object-oriented GDI interface are wrappers around the flat GDI+ API exposed by gdiplus.dll.

While working on my software application, I had used integers internally with a resolution of 1000 dots per inch. I just did not want to deal with floating-point numbers, particularly with equality tests. Since then, I have been experiencing a variety of display errors when doing matrix transformations or changing the zoom level of my document window.

My advice is to always use floats. Internally, the flat GDI+ API only uses floats, so you start out with a maximum of 24 bits of precision, not 32 bits. Secondly, additional precision is lost because of truncation of decimal value when converting from floating-point numbers to integers.

In the course of converting my code to use floats, I discovered a few bugs in the .NET API. Offset is declared public for Point, but private for PointF. A PointF has no explicit type conversion to a SizeF, like its integer counterpart, although there is a SizeF constructor that will accept a PointF. Yuch.. You can see why every new Windows API must pass a mandatory FXCop review.

Thus, I also you leave you with a warning: PointF is less tested than its Point counterpart.

Comments

 

Navigation

Categories

About

Net Undocumented is a blog about the internals of .NET including Xamarin implementations. Other topics include managed and web languages (C#, C++, Javascript), computer science theory, software engineering and software entrepreneurship.

Social Media