参考:
http://stackoverflow.com/questions/5751749/how-can-i-read-bmp-pixel-values-into-an-array
http://msdn.microsoft.com/en-us/library/dd183374%28v=VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/dd183376%28v=VS.85%29.aspx
本文代码和测试图片下载
【测试图片】
宽50像素,高100像素,每个像素的颜色:Red=30, Green=50, Blue=80,在Windows mspaint.exe中保存为 24-bit Bitmap (.bmp)文件
【代码】
- bmp_header_def.h
#ifndef _BMP_HEADER_DEF_H_
#define _BMP_HEADER_DEF_H_
typedef int LONG;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER {
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMet