+ 3

C programming: 24 bit BMP files

I’m attempting to create a program that will read a 24bit BMP file and be able to output just the blue channel image, just the green channel image and just the red channel image. If you have any advice/tips on how to get started, please feel free to share!!

11th Apr 2019, 3:25 PM
Max Elgert
1 Answer
+ 3
If you are on windows you can use the BITMAPFILEHEADER and BITMAPINFOHEADER structs found in <windows.h> Basically a bmp file is a BITMAPFILEHEADER followed by a BITMAPINFOHEADER followed by the binary data of the image. So you need to read the bmp into memory, cast the first few bytes to a fileheader, what comes after it to an infoheader, and whatever is left is all the pixels (r,g,b,r,g,b,r,g,b,...) The infoheader has a bunch of data but if you know your image is 24 bit color depth already then all you need from it are the biWidth and biHeight properties. Hope that helps. I had some bmp code somewhere but I can't find it atm. But if you need help just let me know.
11th Apr 2019, 8:31 PM
Schindlabua
Schindlabua - avatar