You can easily get the integer value of each color of the three colors involved in a pixel (RGB). You can search on the net for the bmp file format. Once you have that you can see that such file has some field that give some information about the file, like size, amount of colors, the palette, etc.
Most of those images have a palette in order to make it smaller. Here is how it works:
Each pixel is normally represented with three bytes, that means 1 byte/pixel. That means that you can have 256 different colors for each R,G or B pixel. That gives you a total of 16 million colors (power(2,24)). The thing is that you might know that an image is a matrix of pixels and having 3 bytes per pixel in a 1024*800 screen is quite a lot. In a 200 x 100 matrix that would be 20m. So they made an interesting think to minimize space. They use a 256-position palette. Each palete has a 3-byte pixel. That allows the image to have only 256 different colors but those 256 could be from a 16 million selection. So each pixel is represented with a 1-byte index to such palette.
So after all the information on the head of the file, you find the palette and after the palette you find the index for each pixel.
You can use any programing lenguaje to extract those pixels, such as java, c/c++, etc, using file streams.
You get each index, find the value of the 3-bytes pixel in the palette and manipulate them as you want.
For example if you want to convert it to white/black, you take an average of the three bytes of the pixel and assign it to each RGB value. That must be done on the palette values.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.