tags:

views:

493

answers:

2

Hello, i got a question for reading an bmp image. How can i get the pixel value(R, G, B values) in an bmp image? Can anyone help me using the C programming language?

+2  A: 

The easy way would be to find a good image manipulation library for your chosen platform and use that.

The hard way would be to open the file and actually interpret the binary data within. To do that you'll need the BMP File Specification. I'd recommend trying the easy way first.

Adam Luchjenbroers
+1  A: 

You need to study the BMP file format. It is easier to read uncompressed 24-bit BMP files. They just contain a header at the beginning and RGB values of each pixel.

To start with this, check the example of 2x2 bitmap image at http://en.wikipedia.org/wiki/BMP%5Ffile%5Fformat. Follow the below steps.

  1. Create the 2x2 BMP image shown on Wikipedia.
  2. Open the file in binary mode using your C program.
  3. Seek to byte position 54.
  4. Read 3 bytes.

The bytes would be 0, 0 and 255 respectively. (Not sure whether the order is RGB. I had done this long back and I think the order is not RGB. Just verify this.)

As simple as that! Study the header of the BMP to understand more about the format.

Madhu