2

みなさん、こんにちは!

このimage.bmpを取得しました。すべてのパディングを含めて読んだ場合、この結果が得られます。

画像を逆さまに読む以外に、ここで何が間違っているのですか?ウィキペディアやグーグルで親戚は見つかりません。24ピクセル幅の後、画像は8ピクセルでミラーリングされているようです。なぜ!?理解できません!?どうすればこれを修正できますか!?

WindowsでC++コードを使用してファイルを読み取り、BMPファイルを未加工で読み取っています。画像ファイルはモノクロです。ピクセルあたり1ビット。

ビットマップデータを表示するためのコード:

unsigned int count = 0; // Bit counting variable
unsigned char *bitmap_data = new char[size]; // Array containing the raw data of the image

for(unsigned int i=0; i<size; i++){ // This for-loop goes through every byte of the bitmap_data

    for(int j=1; j<256; j*=2){ // This gives j 1, 2, 4, 8, 16, 32, 64 and 128. Used to go through every bit in the bitmap_data byte

        if(count >= width){ // Checking if the row is ended
            cout << "\n"; // Line feed

            while(count > 32) count -=32; // For padding.
            if(count < 24) i++;
            if(count < 16) i++;
            if(count < 8) i++;

            count = 0; // resetting bit count and break out to next row
            break;
        }

        if(i>=size) break; // Just in case

        count++; // Increment the bitcounter. Need to be after end of row check

        if(bitmap_data[i] & j){ // Compare bits
            cout << (char)0xDB; // Block
        }else{
            cout << (char)' ';  // Space
        }
    }
}

前もって感謝します!

4

1 に答える 1

4

ほぼ確実に、各バイトのビットを間違った順序で解釈/出力しています。これにより、8ピクセルの各列が左から右に反転します。

BMP形式では、左端のピクセルが上位ビットであり、右端のピクセルが最下位ビットであると記述されています。あなたのコードでは、あなたはビットを通して間違った方法を繰り返しています。

于 2013-03-04T14:58:16.427 に答える