Image Loader

     When working on a side project around Christmas 2008, I needed to load an image into a matrix with RGB values. I remember googling around for a solution several times, but everyone's code was always way more complex than it needed to be. So, I got my brother to do it for me.

     Below I have posted a VC++ 9.0 project that loads a .bmp (it works with other file types, e.g. jpg), as well as the source alone (it is very short), and an image to test it on. The code below is a version I wrote based on my brother's code - I cleaned it up and added comments so it would be as simple as possible.

     Yes, I am aware that the comments were hastily made with many spelling mistakes. The general idea is that you call gdiSetup(true) at the beginning of your program, and gdiSetup(false) at the end. Between those two calls, you can load an image with the line Bitmap b(L"foo.bmp", false); You can then call functions like b.GetWidth(), b.GetHeight(), b.GetPixel(0,0, &c) // where c is defiend as "Color c;" Check out main.cpp to see a simple program that uses these calls.

     I would like to point out that this is NOT a guide or tutorial on loading images. This is meant to be simple code so you can repidly implement your crazy ideas. Also, I suspect that it is easy to save a Bitmap object to a file, though I never looked into it. If you do, send me the code!

A screenshot of the program being run on the test image:

Source (1.92KB .cpp = plain text)
Source Project (5.41KB .zip)
Test Image (29.3KB .bmp)
Take me home
Created: 6-24-2009. Last Modified: 6-24-2009. © Philip S. Thomas