WRITE_BMP

The WRITE_BMP procedure writes an image and its color table vectors to a Microsoft Windows Version 3 device independent bitmap file (.BMP).

WRITE_BMP does not handle 1-bit-deep images or compressed images, and is not fast for 4-bit images. The algorithm works best on images where the number of bytes in each scan-line is evenly divisible by 4.

This routine is written in the IDL language. Its source code can be found in the file write_bmp.pro in the lib subdirectory of the IDL distribution.

Calling Sequence

WRITE_BMP, Filename, Image[, R, G, B]

Arguments

Filename

A scalar string containing the full pathname of the bitmap file to write.

Image

The array to write into the new bitmap file. The array should be scaled into a range of bytes for 8- and 24-bit deep images. Scale to 0-15 for 4 bit deep images. If the image has 3 dimensions and the first dimension is 3, a 24 bit deep bitmap file is created. Note: for 24-bit images, color interleaving is blue, green, red: Image[0,i,j] = blue, Image[1,i,j] = green, etc.

R, G, B

Color tables. If omitted, the colors loaded in the COLORS common block are used.

Keywords

FOUR_BIT

Set this keyword to write as a 4-bit device independent bitmap. If omitted or zero, an 8-bit deep bitmap is written.

IHDR

Set this keyword to a BITMAPINFOHEADER structure containing the file header fields that are not obtained from the image itself. The fields in this structure that can be set are: bi{XY}PelsPerMeter , biClrUsed , and biClrImportant .

HEADER_DEFINE

If this keyword is set, WRITE_BMP returns an empty BITMAPINFOHEADER structure, containing zeros. No other actions are performed. This structure may be then modified with the pertinent fields and passed in via the IHDR keyword parameter. See the Microsoft Windows Programmers Reference Guide for a description of each field in the structure.

Note: this parameter must be defined before the call. For example:

H = 0

WRITE_BMP, HEADER_DEFINE = H

Examples

The following command captures the contents of the current IDL graphics window and saves it to a Microsoft Windows Bitmap file with the name test.bmp :

WRITE_BMP, 'test.bmp', TVRD()

The following commands scale an image to 0-15, and then write a 4-bit BMP file, using a grayscale color table:

r = BYTSCL(INDGEN(16)) ; Create a ramp from 0 to 255

WRITE_BMP, 'test.bmp', BYTSCL(Image, MAX=15), r, r, r, /FOUR

See Also

READ_BMP