WRITE_BMP
Syntax | Arguments | Keywords | Examples | Version History | See Also
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.
Syntax
WRITE_BMP, Filename, Image[, R, G, B] [, /FOUR_BIT] [, IHDR=structure] [, HEADER_DEFINE=h{define h before call}] [, /RGB]
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, Image[2, i, j] = red.
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.
Tag names in the a BITMAPINFOHEADER structure are as defined in the Microsoft Developer Network Library; see http://msdn.microsoft.com/en-us/library/ms532290.aspx for details.
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:
RGB
Set this keyword to reverse the color interleaving for 24-bit images to red, green, blue: Image[0, i, j] = red, Image[1, i, j] = green, Image[2, i, j] = blue. By default, 24-bit images are written with color interleaving of blue, green, red.
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. Note that this works only on a PseudoColor (8-bit) display:
The following lines create an image in an IDL graphics window, read it from the window and write it as a .bmp file in the temporary directory, then read the .bmp file and display it in the same graphics window:
The following commands scale an image to 0-15, and then write a 4-bit BMP file, using a grayscale color table:
Version History