Untitled
By: a guest | Mar 19th, 2010 | Syntax:
C++ | Size: 0.66 KB | Hits: 62 | Expires: Never
Image::Image(string filename)
{
fstream pmgfile;
pmgfile.open(filename.c_str(), ios::binary | ios::in);
if (! pmgfile)
{
cout << "Could not open file " << filename << endl;
return;
}
string temp;
string size;
while (temp != "255")
{
size = temp;
getline(pmgfile, temp);
}
istringstream iss(size);
iss >> rows >> cols; // reading in the size of the data block
datablock = new unsigned char* [rows];
for (int i = 0; i < rows; i++)
datablock[i] = new unsigned char [cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
pmgfile >> datablock[i][j]; // reading in the data values
pmgfile.close();
}