dhpoware logo
home products source demos contact us
navbar navbar
box top left corner box top right corner
Bitmap Class.

The Bitmap class is a simple wrapper around the Win32 DIB (Device Independent Bitmap) API.

The Bitmap class uses GDI+ to load images. The Bitmap class can import the following image file formats: BMP, GIF, JPEG, PNG, TIFF, and TGA. The Bitmap class can export its pixel data to the following file formats: BMP, GIF, JPG, PNG, TGA, and TIF. Once an image is loaded into the Bitmap class methods are provided to allow direct access and manipulation of the pixel data.

Also supported is the ability to capture a screen shot of the Windows desktop and loading that as an image into the Bitmap class.

All Win32 DIBs are aligned to 4-byte (DWORD) memory boundaries. This means that each row of pixels in the DIB is padded with extra bytes to ensure that the next row of pixels starts on a memory boundary that is a multiple of 4-bytes. The Bitmap class takes care of these details. Overloaded array operators are provided to allow the pixel data to be accessed like a 2D array.

Since the Bitmap class makes use of GDI+ applications using the Bitmap class must link to the gdiplus.lib import library.

An earlier version of the Bitmap class originally appeared on flipcode as the DIB24 class.

zip file Download source.

Change History:

13 June 2010.
Updated solution to Microsoft Visual Studio 2010.

4 July 2009.
Added the loadImage() method to replace the existing loadBitmap(), loadPicture(), and loadTarga() methods.
Added the saveImage() method to replace the existing saveBitmap(), and saveTarga() methods. The saveImage() method supports the following image file formats: BMP, GIF, JPG, PNG, TGA, and TIF.

30 June 2009.
The Bitmap class now uses GDI+ to load image files. The following image files can now be loaded into the Bitmap class: BMP, GIF, JPEG, PNG, TIFF, and TGA. All image files that GDI+ supports can now be loaded via the Bitmap class' loadPicture() method.

The older version of the Bitmap class that loaded image files using the IPicture COM interface is no longer supported and is now only available upon request.

5 August 2007.
Updated the grayscale conversion formula to Y = 0.2125R + 0.7154G + 0.0721B. This formula is based on modern CRT and HDTV phosphors and is the same one that Real-Time Rendering Second Edition (Moller and Haines 2002) recommends.

15 October 2006.
Updated the implementation of fill() with a more optimised version. Updated the implementation of resize(). The nearest neighbour sampling filter has been replaced with a bilinear sampling filter. Bilinear sampling provides superior image quality compared to nearest neighbour sampling. However bilinear sampling is slower than nearest neighbour sampling.

30 August 2006.
Added flipHorizontal(), flipVertical(), resize(), and saveTarga() methods. When saving as a Targa (TGA) file the resulting file will always have a colour depth of 32-bits. The resize() method currently supports nearest neighbour sampling only. A future version will support bilinear sampling.

10 June 2006.
The Bitmap class' internal pixel depth is now 32 bits per pixel. All existing file importing methods have been updated to perform automatic colour conversion to the Bitmap class' new 32-bit pixel depth. A new loadTarga() method had been added. This method allows the importing of 8-bit (grayscale), 24-bit, and 32-bit TGA files.

box bottom left corner content box box bottom right corner
logo logo