문제

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

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top