By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,599 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,599 IT Pros & Developers. It's quick & easy.

How to find out a color from .bin file

P: 13
Hello people

am working on bmp files and i am given a task of detecting the color form the bmp file....so i converted the bmp file in hex file that is .bin file and now it is becoming a pain to serch for the color red in the bin file....could anyone plz suggest me a way as to how to read the bin file and how to serch for the red color in the file...
hope to find some solution...
Nov 13 '06 #1
Share this Question
Share on Google+
6 Replies


sivadhas2006
100+
P: 142
Hi,

BMP files are written with respect to the header information.
If you know the header of the bmp file, you can easily get the information of color. i.e., pixel value.

Try the links.

http://web.uccs.edu/wbahn/ECE1021/ST...fileformat.htm

http://local.wasp.uwa.edu.au/~pbourke/dataformats/bmp/



Regards,
M.Sivadhas.
Nov 13 '06 #2

P: 13
Thank you for the response....but what i have worked on is that i have removed the header file in the .bin file...what i mean to say is that the .bin file that i am workin on does not have the header.(coz i have removed it...)..now i want to search this resulting bin file and find out the color...that is red... any code to locate the color red will be very much appreciated.....

Regrds
Ranjit
Nov 13 '06 #3

sivadhas2006
100+
P: 142
Hi,

Can I know what is the format the data stored in the bin file.
i.e., RGBA, ARGB or just RGB.

R Stands for Red,
G Stands for Green,
B Stands for Blue and
A Stands for Alpha.

Regards,
M.Sivadhas.
Nov 14 '06 #4

P: 13
hi

It is in RGB format.....

Thanks a lot ...
Regards
Ranjit
Nov 14 '06 #5

100+
P: 111
Hai ranjitneo

The color is stored as BGR If it is a 24 bit and 4th byte is reserved.

B = Blue
G = Green
R = Red


.
Nov 15 '06 #6

100+
P: 145
Well, you could just read the file using any one of the bitmap libraries out there, and directly access the pixels.

If you want info on the BMP file format, I'd look here: http://www.fortunecity.com/skyscrape.../bmpffrmt.html

It will tell you how many bytes you need to strip out until you reach the first amount of data. If it's not a 24-bit or 32-bit image, however, it will be a bit more difficult. (color tables and/or bit masks, etc.)

That reference was particularly helpful to me for writing my own bitmap library.
(EasyBMP)

If you choose to use that, it's as follows:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. #include "EasyBMP.h"
  3. ..
  4.  
  5. // declare and read an image
  6.  
  7. BMP Image;
  8. Image.ReadFromFile( "my_image.bmp" );
  9.  
  10. // get info on pixel (3,12)
  11.  
  12. cout << "Pixel (3,12) : (" 
  13.        << Image(3,12)->Red << " , " 
  14.        << Image(3,12)->Green << " , " 
  15.        << Image(3,12)->Blue << ")" << endl;
  16.  
  17. // change pixel (4,3) to the color (255,0,128):
  18.  
  19. Pixel(4,3)->Red = 255;
  20. Pixel(4,3)->Green = 0;
  21. Pixel(4,3)->Blue = 128;
  22.  
  23. // save the modified image
  24.  
  25. Image.WriteToFile( "modified_image.bmp" );
  26.  
That's it. :) -- Paul
Nov 15 '06 #7

Post your reply

Sign in to post your reply or Sign up for a free account.