The Basics of Bitmap Images


Images in windows games are represented by bitmaps , which are rectangular graphics objects containing rows and columns of little squares called pixels . The name bitmap comes from the fact that the rows and columns determine how to map the pixels to the screen; the pixels themselves are composed of bits. Each pixel in a bitmap is a solid color. In fact, the only information associated with a pixel is its color . So, you can think of a bitmap as a rectangular arrangement of little colored squares. If you're old enough to remember the popular Lite Brite toy, you definitely have an understanding of how a bitmap works. Lite Brite, which is still manufactured today by Hasbro, allows you to plug colored pegs into a black plastic grid to draw pictures.

graphics/book.gif

Two types of bitmaps are supported in Windows: device-dependent bitmaps and device-independent bitmaps . Device-dependent bitmaps are stored in a manner determined by a specific device, whereas device-independent bitmaps are stored in such a way that they can be displayed on any device. All the bitmaps you work with in this book are device-independent bitmaps, which are sometimes referred to as DIBs . Just keep in mind that when I refer to "bitmaps" from here on, I'm really referring to DIBs.


You are probably familiar with bitmaps from the popular .BMP file type that is used throughout Windows. BMP is the standard image format used in Windows, and is also the format you'll be using to work with bitmaps throughout this book. Although GIF and JPEG have certainly surpassed BMP as image formats for use on the Web, BMP is still used a great deal by Windows users. Not only that, but the BMP image format is considerably simpler and easier to work with at a programming level than GIF and JPEG. You can use the standard Paint program built into Windows to create and edit BMP files, or use Microsoft Photo Editor, which offers more features for working with photographic images.

Although there is only one bitmap image format, not all bitmap images are created equal. First of all, the bitmap image format allows you to create bitmaps with varying numbers of colors. More specifically , you can create 8-bit bitmaps that use 256 (palletized) colors or 24-bit bitmaps that use more than 16 million colors. You can also create bitmaps that use a technique known as compression to help reduce the size of the bitmap file. To help keep the code simple, the bitmaps you use throughout the book are limited to 8-bit uncompressed bitmaps. This is very important to remember because other types of bitmaps won't work with the bitmap code you develop in this hour .

Regardless of how you create a bitmap, it ultimately ends up as a file with a .BMP file extension. To use such a bitmap in a Windows program, you have two options:

  • Read the bitmap directly from the file

  • Store the bitmap as a resource and read it from memory

In the first option, the Windows program opens the bitmap file from disk and reads in the image data. It then uses the bitmap image data to create a GDI bitmap graphics object that can be drawn to a device context. The second option involves storing a bitmap as a resource within the executable program, which means that you don't have to include the bitmap file with the program once it is compiled. The advantage to this option is that you are able to distribute your game as a single program file. Fortunately, the bitmap class you create later in this hour supports both approaches to using bitmaps.



Sams Teach Yourself Game Programming in 24 Hours
Sams Teach Yourself Game Programming in 24 Hours
ISBN: 067232461X
EAN: 2147483647
Year: 2002
Pages: 271

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net