Written by Mike D Sutton
EDais@mvps.org

Http://EDais.mvps.org/

- 15.01.2005 -

What is a DIB?:

DIB stands for “Device Independent Bitmap” and as its name suggests allows for storage and manipulation of image data independent from the limitations of the device it’s used with. A DIB on its own is more of a concept than something we use directly in GDI development, representing the storage of bitmap data and a header that describes the data format. There are a number of derived Bitmap types which stem from this; namely the Packed DIB, the .BMP (and/or .DIB) file format and DIBSection objects.

A Packed DIB is a chunk of memory that stores the Bitmap information and can be passed around as a single memory object, which makes it perfect for use with low level graphical-based libraries and the clipboard.

The .BMP file format is nothing more than a Packed DIB with an additional file header structure prefixing the data, which makes conversion between disk and memory DIBs an easy task.

The DIBSection effectively encapsulates a DIB behind the scenes and exposes it as a GDI Bitmap handle, which allows us to use it in conjunction with the GDI infrastructure similar to its cousin the DDB.

The majority of this article will focus on the latter for the three DIB types which is generally the most used, however the other two will also be covered.

This article assumes a reasonable prior knowledge of GDI development in VB, the DC and DDB articles on the EDais site are a good primer for the code covered in this article which I’d strongly recommend reading through first.
Also a reasonable familiarity with memory direct manipulation in VB would be advisable, again the direct memory manipulation article on the EDais site is a good introduction to that topic.

Note; Unlike other articles on the site, this is considered only a first half or an introductory article on the subject, a second article is in production as time permits which will further explore these concepts and go through the construction of classes to encapsulate the functionality.
Please check back on the EDais site for more information about the second part and other articles in the series.

Chapter index:

You can download this tutorial to disk for easier viewing offline as an Adobe Acrobat PDF:

Adobe Acrobat PDF doccument (362kb)

And the code for all the chapters:

Code (10kb)

Move on to chapter 1
Back to tutorials