You can try the following:
unsigned char* readBMP(char* filename) { int i; FILE* f = fopen(filename, "rb"); unsigned char info[54]; fread(info, sizeof(unsigned char), 54, f);
data should now contain (R, G, B) pixel values. The pixel color (i, j) is stored in data[3 * (i * width + j)] , data[3 * (i * width + j) + 1] and data[3 * (i * width + j) + 2] .
In the last part, a swap between each first and third pixel is performed because the windows store the color values as (B, G, R), and not (R, G, B).
0605002
source share