0
BMP 이미지 파일을 메모리로 읽으려고하지만 코드가 eof를 일찍 지킵니다. 읽은 픽셀이 올바른 것처럼 보입니다. eof는 각 파일의 동일한 위치에서 반복적으로 발생하지만 파일간에 반복 가능한 공통 패턴은 없습니다.ifstream 이른시기에
1024 x 1024 image: file length = 3145782, bytes read = 6154.
256 x 256 image: file length = 196662, bytes read = 24243.
256 x 256 image2: file length = 196662, bytes read = 931.
나는 약간의 의견을 고맙게 여길 것입니다. 다음은 내 코드의 단축 버전입니다. 나는 가독성을 위해서만 안전 체크와 같은 것들을 제거했다.
std::ifstream file(filename, std::ios::in || std::ios::binary);
file.seekg(0, file.end);
int length = file.tellg();
file.seekg(0, file.beg);
std::cout << "file length = " << length << "\n";
//Read Header in and confirm this is actuall a bmp file.
file.read((char*)header, 54);
dataPos = *(int*)&(header[0x0A]);
imageSize = *(int*)&(header[0x22]);
width = *(int*)&(header[0x12]);
height = *(int*)&(header[0x16]);
std::cout << imageSize << "," << width << "," << height << "\n";
data = new unsigned char[imageSize];
file.read((char*)data, imageSize);
std::cout << "bytes read: " << file.gcount() << "\n";
file.close();
당신은 논리 || 비트 연산자 대신에 연산자 | 연산자는 스트림 플래그 매개 변수 –
@MassimilianoJanes 내 하나님, 고마워요. 당신이 대답을 게시하면 나는 그것을 올바르게 표시 할 것입니다. – Kits