1.写操作
int bmp_write(unsigned char* image, int imageWidth, int imageHeight, const char* filename){
long extrabytes = 4 - ((imageWidth * 3) % 4);
if (extrabytes == 4)
extrabytes = 0;
long paddedsize = ((imageWidth * 3) + extrabytes) * imageHeight;
unsigned char header[54] = {
0x42, 0x4d, 0, 0, 0, 0, 0, 0, 0, 0,
54, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
long file_size = paddedsize + 54;
header[2] = (unsigned char)(file_size & 0x000000ff);
header[3] = (file_size >> 8) & 0x000000ff;
header[4] = (file_size >> 16) & 0x000000ff;
header[5] = (file_size >> 24) & 0x000000ff;
long width = imageWidth;
header[18] = width & 0x000000ff;
header[19] = (width >> 8