-2

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.

Eddy Freddy
  • 1,820
  • 1
  • 13
  • 18
Sahi
  • 17
  • 2
  • 5

2 Answers2

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