Height and Width of Image using C++

Hello all. Is there a way of finding the height and width from the *.bmp file either through its header file or another way? I'm currently using Visual Studio 2010. I recognise that the header file is 54 bytes.

I currently have this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ifstream image;
image.open("image.bmp",std::ios_base::binary);

if (image.is_open()) 
{
cout<< "function success\n";
} 
else 
{
cout<< "unable to open file";
}
//get length of file:
image.seekg(0, image.end);
int n = image.tellg();
image.seekg (0, image.beg);

//allocate memory:
char* res = new char[n];

//read data as a block:
image.read(res, n);


Is there a way I can loop through to extract the relevant information? I would appreciate an example if possible.

Thanks in advance!
Last edited on
Would appreciate some guidance and an example.
Topic archived. No new replies allowed.