READ_BMP function reads a Microsoft Windows Version 3 device independent
bitmap file (.BMP) and returns a byte array containing the image. Dimensions are taken from the BITMAPINFOHEADER of the file. In the case of 4-bit or 8-bit images, the dimensions of the resulting array are (
For 24-bit images, the dimensions are (
). Color interleaving is blue, green, red; i.e., Result[
] = blue, Result[
] = green, etc.
READ_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
subdirectory of the IDL distribution.
Result = READ_BMP(
Filename, [, R, G, B [, Ihdr])
A scalar string specifying the full path name of the bitmap file to read.
R, G, B
Named variables that will contain the color tables from the file. There 16 elements each for 4 bit images, 256 elements each for 8 bit images. Color tables are not defined or used for 24 bit images.
A named variable that will contain a structure holding the BITMAPINFOHEADER from the file. Tag names are as defined in the MS Windows Programmer's Reference Manual, Chapter 7.
If this keyword is set, color interleaving of 16- and 24-bit images will be R, G, B, i.e., Result[
] = red, Result[
] = green, Result[2,
] = blue.
To open, read, and display the BMP file named
in the current directory and store the color vectors in the variables R, G, and B, enter:
TV, READ_BMP('foo.bmp', R, G, B)
TVLCT, R, G, B
Many applications that use 24-bit BMP files outside IDL expect BMP files to be stored as BGR. For example, enter the following commands.
a = BYTARR(3, 200, 200)
a(0, *, *) = 255
TV, a, /TRUE
WRITE_BMP, 'foo.bmp', a
If you open the
file in certain bitmap editors, you may find that the square is blue.
READ_BMP, 'foo.bmp', image
TV, image, /TRUE
READ_BMP, 'foo.bmp', image, /RGB
TV, image, /TRUE