Guest
Public paste!

Untitled

By: a guest | Mar 19th, 2010 | Syntax: C++ | Size: 0.66 KB | Hits: 62 | Expires: Never
Copy text to clipboard
  1. Image::Image(string filename)
  2. {
  3.         fstream pmgfile;
  4.         pmgfile.open(filename.c_str(), ios::binary | ios::in);
  5.         if (! pmgfile)
  6.         {
  7.                 cout << "Could not open file " << filename << endl;
  8.                 return;
  9.         }
  10.         string temp;
  11.         string size;
  12.         while (temp != "255")
  13.         {
  14.                 size = temp;
  15.                 getline(pmgfile, temp);
  16.         }
  17.         istringstream iss(size);
  18.         iss >> rows >> cols; // reading in the size of the data block
  19.        
  20.         datablock = new unsigned char* [rows];
  21.         for (int i = 0; i < rows; i++)
  22.                 datablock[i] = new unsigned char [cols];
  23.                
  24.         for (int i = 0; i < rows; i++)
  25.                 for (int j = 0; j < cols; j++)
  26.                         pmgfile >> datablock[i][j]; // reading in the data values
  27.        
  28.         pmgfile.close();
  29. }