Description
I've been using GDI+ in several desktop applications mainly because this API is straightforward and easy to use. GDI+ is a vector graphic library developed by Microsoft. Even though GDI+ has now two serious competitors, it still performs better in several scenarios. By competitor, I'm referring to
Cairo graphics and
Google Skia (the later is part of the Chromium project).
These two are the most promising I've come to know and see being used in real world application. Cairo and Skia are both free and flexible open source alternative that you can use in your native application.
Ok, let's get back to our GDI+ since that's the reason why I'm posting this article. First, I want you to know that most Windows Mobile devices that you will find already come with Gdiplus.dll. This DLL exposes several hundreds of functions through a flat API. Thus, to use the library, you simply use
LoadLibrary(...) to load it and then
GetProcAddress(...) to find the entry point of the function that you need. This step can be very slow. Besides, like I said before GDI+ exports hundreds of functions, it's a whole lot of job calling
GetProcAddress(...) for each one of them. Another drawback of doing this is the fact that on PC, Microsoft already distributed a set of C++ classes which really facilitates using this library. Now, if you were planning to use them, you would be on your own!
Not anymore folks, LibGdiplus is now at your rescue! Be aware though, GDI+ on Windows CE is not fully implemented, several methods simply return
NotImplemented. This is probably the reason why the library has been kept a secret. But it is still worthwhile to use it considering that Cairo has been used to develop GDI+ clone (see the
Mono LibGdiplus project). What this means for you is that it's possible to strip-out portion of the Mono/GDI+ backend and use it where no implementation has been provided.
Note: Don't waste your time trying to build the entire Mono/GDI+ on PC. The Mono version depends on X Window backend, freetype font and several other dependencies. You've been warned!!!
LibGdiplus provides wrapper around the DLL so that you can use it the same way as on your desktop. Some headers have been changed slightly in order to build for Windows CE.
Remember GDI+ on Windows Mobile has several limitations:
- No support to load image file directly from path
Use IStream interface to load file data, use the stream interface version to create bitmap. Same goes for resource.
- Windows Mobile doesn't support the following features:
GDI Path (GDI path functions are not exported)
Enhanced Meta file
When porting GDI+ components for Windows CE, always remember that CE exports around 85 functions of the 400 that exist on the desktop. Region and font API have limited support on this platform as well. GDI Path and world transformation functions are not exported. For these reasons, be judicious about the features you wish to support in your design.
Using GDI+
Since GDI+ headers are not distributed for CE, you need to use the ones that I included here. Use
#include <gdiplus.h> in your code as usual, add
LibGdiplus.lib to your project dependencies.
There is no demo but if you wish to learn GDI+ I think the best I can do here is directing you to MSDN. The links below shall guide if you are new to GDI+.
GDI+ Reference
Using GDI+
Conclusion
In this article, I talked about GDI+ support for Windows Mobile devices. Which is quite limited compared to the desktop version. But this library can be adapted by implementing the missing features using Cairo. Unfortunately, my time was limited for this specific project and I couldn't implement additional features but I hope those who have a need for this will find it useful.
That's all folks! Everything is free, no license restriction.
History
01/21/2009: LibGdiplus - initial release