Ron*_*lic 13
我相信你已经检查过http://en.wikipedia.org/wiki/BMP_file_format.
有了这些信息,我们可以写一个快速的BMP:
// setup header structs bmpfile_header and bmp_dib_v3_header before this (see wiki)
// * note for a windows bitmap you want a negative height if you're starting from the top *
// * otherwise the image data is expected to go from bottom to top *
FILE * fp = fopen ("file.bmp", "wb");
fwrite(bmpfile_header, sizeof(bmpfile_header), 1, fp);
fwrite(bmp_dib_v3_header, sizeof(bmp_dib_v3_header_t), 1, fp);
for (int i = 0; i < 200; i++) {
for (int j = 0; j < 200; j++) {
fwrite(&image[j][i][2], 1, 1, fp);
fwrite(&image[j][i][1], 1, 1, fp);
fwrite(&image[j][i][0], 1, 1, fp);
}
}
fclose(fp);
Run Code Online (Sandbox Code Playgroud)
如果设置标题是一个问题,请告诉我们.
编辑:我忘记了,BMP文件期望BGR而不是RGB,我已经更新了代码(惊讶没人抓到它).