【发布时间】:2013-02-18 16:49:19
【问题描述】:
大家好!
我收到了这个image.bmp。 当我阅读包含所有填充的内容时,我得到this 结果。
除了颠倒阅读图像之外,我在这里做错了什么?我在维基百科或谷歌搜索上找不到任何相关的东西。似乎在 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
}
}
}
提前致谢!
【问题讨论】:
-
你能告诉我们你正在使用的代码吗?除非您这样做,否则我们不会很有帮助。
-
还有EasyBMP,它只用于 BMP 文件,比 FreeImage 具有更基本的功能。