在24位bmp中,像素存储为BGR
,每种颜色只占用1个字节。可以读取
for(i=0;i<heigh*width;i++){ // foreach pixel
image[i][2] = getc(streamIn); // use BMP 24bit with no alpha channel
image[i][1] = getc(streamIn); // BMP uses BGR but we want RGB, grab byte-by-byte
image[i][0] = getc(streamIn); // reverse-order array indexing fixes RGB issue...
printf("pixel %d : [%d,%d,%d]n",i+1,image[i][0],image[i][1],image[i][2]);
}
但在256色bmp中,每个像素只需要1个字节,所以我如何读取此图像并获得所有像素值?
256有一个查找表来映射字节值。
http://en.wikipedia.org/wiki/BMP_file_format
谷歌一些代码:(未经测试)
http://paulbourke.net/dataformats/bmp/parse.c