Bitmap images
Introduction
We can think of an image on a computer as being stored as a series of squares. These squares are known as 'pixels' and are defined as 'a single dot in an image' . Exactly how does the computer use pixels to store an image?
Displaying pictures using bitmaps
Consider the image above. The smallest unit element that can be displayed is the 'pixel' which is a shortened word that originates from the phrase 'picture element'. If we want to store the picture, we have to start in the top-left hand corner and store the colour (often referred to as the ‘colour depth’) of each pixel down to the bottom right-hand square. If we store the information about each of the pixels, we end up with a picture file known as a 'bitmap file'. This is the raw file that you get when you scan a picture using a scanner, for example.
Pixels do not have a length!
It is important to understand that pixels do not actually have a length! You may have a picture that is defined as 400 pixels wide and 200 pixels high, but that is not a measure of physical size. It is only a measure of how many pixels there are in the height and width of a picture. When the image is to be displayed or printed out, that is when the actual size of the picture is defined. For example, if you have a picture that is 400 pixels wide and 200 pixels high, you may want to print it out at a resolution of 100 DPI (one hundred 'Dots Per Inch', which is another way of saying 'pixels per inch'). You can do this by adjusting the settings in the printer software. Your picture will be printed out 4 inches wide by 2 inches high. If you then decided you wanted a more detailed, sharper picture, you might set your printer to a higher resolution, e.g. 400 DPI. Now, the same picture would be printed out and measure just 1 inch by 0.5 inches. Pixels are dimensionless. It is the resolution that you set your screen or printer to that determines the size images will be displayed at.
You should be able to find the settings for your screen's resolution. before you set your screen to a 'higher' resolution than it currently is, what do you expect to happen? What about if you set it to a lower resolution? Now change the resolution and see if you were right. When you next print something out, print it out a few times but with a different DPI. Text is usually fine at 100 DPI but photos may not be. Experiment with different resolutions.
Metadata and file headers
The colour depth information and the resolution are just two pieces of information about a picture that an application needs to display it properly. Other pieces of information about an image are also available to an application that wants to display the image. This might include the type of file it is, the width of the picture and the height. The collective word for this information is 'metadata', which just means 'data about data'. Every image has metadata associated with it. It is stored in the file header for each image file. A typical file header for a Windows bitmap image (BMP) might look something like this:
//
// Header structure for the MS Windows 1.x Bitmap Format
// a BYTE is an unsigned char
// a WORD is an unsigned short int (16-bits)
//
typedef struct _WinHeader1x
{
//
// Type Name Offset Comment
//
WORD Type; /* 00h File Type Identifier (always 0) */
WORD Width; /* 02h Width of Bitmap in Pixels */
WORD Height; /* 04h Height of Bitmap in Scan-lines */
WORD Width; /* 06h Width of Bitmap in Bytes */
BYTE Planes; /* 08h Number of Color Planes */
BYTE BitsPixel; /* 09h Number of Bits Per Pixel */
} OLDWINHEAD;
Bitmap files
If you have ever used the application called Paint in Windows (in Accessories), this application can save any picture you create as a bitmap file (amongst other file types) and it has the file extension bmp. That means that when you save the file, Windows automatically adds .bmp to the end of your file name.
JPG, GIF and other 'codecs'
There is problem with bitmap files. They are very large. That means they take up a lot of storage space, take a while to open and also take a long time to transmit across networks. This is very important with the Internet. You don't want to be waiting for your computer to download and open large bitmap files.
For this reason, image files are usually stored as a different file type. Two common ones are GIF and JPG. These are known as 'codecs' (short for 'coder / decoder') and you can think of each codec as a clever Maths formula. If you take a bitmap and apply the GIF codec to it, it becomes a GIF file and is much smaller than the original bitmap. You can do the same thing using the JPG, or TIFF formats or any of the other image codecs. GIFs are great for icons and drawings that use up to 256 colours and are widely used for icons in software and for pictures on web sites. For more detail such as in photos, JPGs are used. They can use about 65000 colours so you get a lot of detail. So, when you draw a picture on a computer and save it as a particular file type, you are telling the computer to take the raw bitmap file and apply a particular Maths formula or codec to it, and add the correct file extension - .gif or .jpg or whatever it is you saved it as.