I am working on the image processing through c++, I has to read the header of jpeg image in char format, I has to check the camera/system/device information of image, how can i do it.
Asked
Active
Viewed 313 times
-2
-
Is it really a file, or just raw data in a buffer? – K-ballo Oct 23 '11 at 20:44
-
Is you problem really about reading a file, or is it about how to find the meta data for the camera? For meta data, you probably need to ask a much more specific question. – Soren Oct 23 '11 at 21:09
-
1BTW, standard English sentences end with a period, '.', not a comma, ','. – Thomas Matthews Oct 23 '11 at 22:55
2 Answers
1
If the file isn't too big, you can read it all into memory:
#include <vector>
#include <fstream>
std::ifstream infile("thefile.bin", std::ios::binary);
infile.seekg(0, std::ios::end);
const std::size_t filesize = infile.tellg();
std::vector<char> buf(filesize);
infile.seekg(0, std::ios::beg);
infile.read(buf.data(), filesize); // or &buf[0] on old compilers
Your file will be stored in the vector buf
. If you only want to read the header, you can read smaller chunks, rather than all of filesize
, and process them appropriately.

Kerrek SB
- 464,522
- 92
- 875
- 1,084
0
In general, the "meta" section of images are a fixed size.
Read the file, using istream::read
and binary mode into a vector. Using the image format specification, locate the field you need.
Build multibyte integers one byte a time, rather than trying to cast a location as an integer and reading. This will help you overcome the issue of Endianness.

Thomas Matthews
- 56,849
- 17
- 98
- 154