Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi all, I need to read the color

Status
Not open for further replies.

sheila11

Programmer
Dec 27, 2000
251
US
Hi all,

I need to read the color code from an image file. (The code for each pixel.) I am trying it with this simple code, but I get to read the header first. How do I know where the header ends and the body begins?

I can change the file format (to gif, tif, bmp, etc...anything) This is a simple OCR project, and the images are in Black and White.

My code is:
#include <fstream.h>

void main()
{
fstream File(&quot;2.jpg&quot;,ios::eek:ut | ios::in | ios::binary);

char ch;
File.seekg(ios::beg); //go to the file beginning

for(int i=0; i < 11; i++){
File.get(ch); //read one character
cout << ch << &quot; - &quot; <<(int)ch <<endl; //display it
}
File.close();

}
 
With a bitmap, I believe there's a field in the header that contains the byte offset at which the actual data starts. You can find out which field it is by looking up the format of a bitmap file.

However, instead of trying to handle it manually, I'd suggest finding an existing library that deals with bitmaps (or whatever file format you want).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top