What is the BMP format for Gray scale Images?

You're right, BMP only knows about colors. The way to do this is to create a palette of 256 entries, where each entry has the same value for R,G,B: first entry (0,0,0), second entry (1,1,1) etc. Now make the image 8 bits per pixel using the palette.

Edit: given your new requirement for 16 bit grayscale, I think you have 2 choices: convert to 8 bit, or use a different format other than BMP. If you convert to 8 bit, you can use dithering to make a result that is visually indistinguishable from your source 16 bit image.


For grayscale images, I would use 8-bit BMP. 8 bit BMPs can encode colors with palette. However, if you don't use one, you can simply interpret color values [0...255] as colors from black (0) to white (255).

Edit: I wouldn't use BMP for 16-bit grayscale images. Technically, you could use 16-bits per pixel BMP format for encoding 16-bit grayscale data (http://en.wikipedia.org/wiki/BMP_file_format#Pixel_format). However in practice this is a bad idea (read: hacky) since that depth is designed to encode alpha, red, green and blue samples of the pixels.

A better format for storing 16-bit per pixel grayscale data is PNG.

Also ask yourself, do you really, really need that extra-precision? For most applications, 8 bits per pixel is just fine (=if you don't have any specific requirements on precision, this would be the case).