How can I read pixel value of a bitmap file?

Hi,

Suppose I’ve a bitmap file(a.bmp). I want to read it. I want to get the pixel values of this bitmap file. Then I want to store these pixel values in a text file.

Then I want to draw that image on opengl window.

Then I would change some pixel values and save it as b.bmp. The b.bmp will not be same as a.bmp.

How can I do this with opengl? Can someone post sample code?

Any answer will be highly appreciated.

Thanks in advance.

OpenGL is unlikely to be useful here. It’s a rendering API, not an image-processing library.

For C or C++, consider DevIL. Higher-level languages tend to either have image I/O as part of the standard library or have libraries tailored to that language (e.g. PIL/Pillow for Python).

  • Check wikipedia for .bmp specification. Then you should know how a bitmap is built.
  • Use low level IO functions in C to open and read a file.
  • run through the stream with a byte pointer using the right offset.
  • manipulate what ever you want.
  • use low level IO functions to create a new file