Search code examples
carraysrgbbmp

Put BMP image into 2D array and edit RGB values in C


Okay guys, I am new to C and I am a trying to construct a 2D array that will hold a BMP image and be able to edit the RGB values. I haven't been able to find anything online about how to access the RGB values or how to put this image in the 2D array and I am really stuck as to where to start. HELP!!!!


Solution

  • See the reference Writing BMP image in pure c/c++ without other libraries of Ed Heal. Things to note:

    • Define the structures. Don't use arrays of unsigned chars to make the headers as in the referenced post.

    • Both in reading and writing, take care to fill the scanlines. They must be a multiple of four, so the last bytes may not be pixels and contain garbage.

    See also my earlier post What is wrong with this code for writing grey-scale bmp from an image RGB bmp pure C - Windows OS which contains the headers and can serve as a partial example.