简体   繁体   English

每个像素的C ++位图位

[英]C++ Bitmap Bit per pixel

I'm trying to understand building a bmp based on raw data in c++ and I have a few questions. 我试图理解在c ++中基于原始数据构建bmp,我有几个问题。

My bmp can be black and white so I figured that the in the bit per pixel field I should go with 1. However in a lot of guides I see the padding field adds the number of bits to keep 32 bit alignment, meaning my bmp will be the same file size as a 24 bit per pixel bmp. 我的bmp可以是黑白的,所以我认为在每像素位字段中我应该使用1.然而在很多指南中我看到填充字段添加了位数以保持32位对齐,这意味着我的bmp将与每像素bmp 24位相同的文件大小。

Is this understanding correct or in some way is the 1 bit per pixel smaller than 24, 32 etc? 这种理解是正确的还是在某种程度上是每像素1位小于24,32等?

Thanks 谢谢

Monochrome bitmaps are aligned too, but they will not take as much space as 24/32-bpp ones. 单色位图也是对齐的,但它们不会占用24/32-bpp的空间。

  • A row of 5-pixel wide 24-bit bitmap will take 16 bytes: 5*3=15 for pixels, and 1 byte of padding. 一行5像素宽的24位位图将占用16个字节:5 * 3 = 15个像素,1个字节的填充。
  • A row of 5-pixel wide 32-bit bitmap will take 20 bytes: 5*4=20 for pixels, no need for padding. 一行5像素宽的32位位图将占用20个字节:5 * 4 = 20个像素,无需填充。
  • A row of 5-pixel wide monochrome bitmap will take 4 bytes: 1 byte for pixels (it is not possible to use less than a byte, so whole byte is taken but 3 of its 8 bits are not used), and 3 bytes of padding. 一行5像素宽的单色位图将占用4个字节:像素为1个字节(不可能使用少于一个字节,因此不占用整个字节,但不使用其中的4个中的3个),以及3个字节的填充。

So, monochrome bitmap will of course be smaller than 24-bit one. 因此,单色位图当然会小于24位。

The answer is already given above (that bitmap rows are aligned/padded to 32-bit boundary), however if you want more information, you might want to read DIBs and Their Uses , the "DIB Header" section - it explains in detail. 上面已经给出了答案(位图行对齐/填充到32位边界),但是如果您想要更多信息,可能需要阅读DIB及其用途 ,“DIB标题”部分 - 它会详细解释。

Every scanline is DWORD-aligned. 每条扫描线都是DWORD对齐的。 The scanline is buffered to alignment; 扫描线被缓冲到对齐; the buffering is not necessarily 0. 缓冲不一定是0。

The scanlines are stored upside down, with the first scan (scan 0) in memory being the bottommost scan in the image. 扫描线上下颠倒存储,内存中的第一次扫描(扫描0)是图像中最下面的扫描。 (See Figure 1.) This is another artifact of Presentation Manager compatibility. (参见图1.)这是Presentation Manager兼容性的另一个工件。 GDI automatically inverts the image during the Set and Get operations. GDI在Set和Get操作期间自动反转图像。 Figure 1. (Embedded image showing memory and screen representations.) 图1.(显示内存和屏幕表示的嵌入式图像。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM