READ_BMP
Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also
The READ_BMP function reads a Microsoft Windows Version 3 device independent bitmap file (.BMP) and returns the image.
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 read_bmp.pro in the lib subdirectory of the IDL distribution.
Note
To find information about a potential BMP file before trying to read its data, use the QUERY_BMP function.
Syntax
Result = READ_BMP( Filename, [, R, G, B] [, Ihdr] [, /RGB] )
Return Value
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 (biWidth, biHeight).
For 24-bit images, the dimensions are (3, biWidth, biHeight). Color interleaving is blue, green, red; i.e., Result[0,i,j] = blue, Result[1,i,j] = green, etc.
Arguments
Filename
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.
Ihdr
A named variable that will contain a structure holding the BITMAPINFOHEADER from the file. Tag names are as defined in the Microsoft Developer Network Library; see http://msdn.microsoft.com/en-us/library/ms532290.aspx for details.
Keywords
RGB
If this keyword is set, color interleaving of 16- and 24-bit images will be R, G, B, i.e., Result[0,i,j] = red, Result[1,i,j] = green, Result[2,i,j] = blue.
Examples
To open, read, and display a BMP file named foo.bmp in the current directory and store the color vectors in the variables R, G, and B, enter:
Many applications that use 24-bit BMP files outside IDL expect BMP files to be stored as BGR. For example, enter the following commands.
If you open the .bmp file in certain bitmap editors, you may find that the square is blue.
Version History
See Also