Reputation: 135
I want to load a 16-bit binary PGM image with a size of 4096x4096 pixels using std::ifstream. The problem is that I can only load smaller files, eg. 512x512. If I try to load the "large" one the data I get is always 0 for every pixel.
Example Code:
int size = width*height;
unsigned short* data = new unsigned short[size];
// Read the terrain data
for(int i = 0; i < size; i++)
{
file >> data[i];
}
If I set size manually to a lower value, this seems to work. Any idea?
Thx Tim
Upvotes: 0
Views: 1367
Reputation: 96810
operator >>
should not be used for binary extraction operations. Instead, by using read
the file will simply input the bytes:
file.read(reinterpret_cast<char*>(data), sizeof data);
Upvotes: 1