Sunday, February 3, 2013

Adventures with Images in Mono

So, the last little while I've been working a lot with images in Mono. Mono is a cross platform version of C#. The applications I'm working on need to run on both Mac and Windows. My first thought was to just use the System.Bitmap class. It was built into .Net and I've used it before in windows only applications. I wrote a fair bit of code using the bitmap class, did a few tests and everything seemed to be working great. Then I booted my machine to OSX. All of the images were now coming out with pre multiplied alpha. The difference was tracked down to how the bitmap was being loaded. The png files were getting the alpha pre multiplied on load. The quick fix for this was to unpremultiply the alpha on load. The bigger fix was to find cross platform imaging library that worked well in Mono. After trying a few, the built in Gdk libraries and imagemagick. I stumbled upon FreeImage. Using this library was a breeze. The dll for windows can be downloaded from their site, and the Mac version can be installed through macports. There is also a c# binding project on their site. Overall it is a really nice library to use. I have not done benchmarks, but it seems very fast, it is full featured, and it's really easy to use. You should defenatily check it out if your looking for a nice imaging library.

No comments:

Post a Comment