Februray 7th Wednesday (一月 七日 水曜日)

时间:2022-06-27 14:02:12

  I learned how to display a bitmap file at Windows.  A normal bitmap file is consist of four parts:
BITMAPFILEHEADER, BITMAPINFOHEADER, Palette, ImageData.  The palette is an array of colors.  Every
pixel datum is an index of that palette.  In this way, the size of a bitmap file can be reduced.

  The size of BITMAPFILEHEADER is just 14 bytes.  The first member of it is "bfType", which is used
to check whether this file is a bitmap file.  Normally, its value in a bitmap is 0x424D -- "BM".  The
second member is "bfSize" that is store the size of the whole bitmap file.  "bfOffBits" is its last
member, which tell us where is the begin of image data in the bitmap file.

  In BITMAPINFOHEADER, "biBitCount" is one of its important member.  It not only represent which color
mode is a bitmap file, but also indicate how many bytes is used to present a pixel on screen.  The 24
bits true color mode has so much color that a bitmap file in true color has no its own palette.  In that
case, every pixel is represented by three byte -- R, G, B.

  I wrote a function to load a bitmap file by specified file name.  Because of the vice of Windows APIs,
my load function have to create a block of memory depending on a device context.  The device context likes
a buffer behind a window object.  So, when repainting a window it copy data from the buffer to the screen.
In this way, a bitmap file is displayed on the screen.