如何理解bmp的bitmapinfoheader中的biBitCount和biClrUsed?

「已注销」 2010-06-20 03:28:07
biClrUsed,说是实际用到的颜色数目,如何理解?若为零,则与bibitcount有关?
我用了两个DIB类:(A),(B)来进行位图显示,结果,有一个类出现了错位,发现(A)类计算颜色表项数改为256,也能正常显示,但源图像为24位深的位图。若不改,颜色表项数改为0,但是有错位,并且每个像素的颜色也发生了变化?不明白为什么?
(B)类可以正常显示,主要是对biBitCount和biClrUsed进行了操作,代码如下:
/*************************************************************************
* DIBNumColors()
*
* Return Value:
* WORD - number of colors in the color table
*
* Description:
* This function calculates the number of colors in the DIB's color table
* by finding the bits per pixel for the DIB (whether Win3.0 or other-style
* DIB). If bits per pixel is 1: colors=2, if 4: colors=16, if 8: colors=256,
* if 24, no colors in color table.
************************************************************************/
WORD CDibImage::DIBNumColors() const
{
if (!m_pBMI)
return 0;

WORD wBitCount; // DIB bit count

/* The number of colors in the color table can be less than
* the number of bits per pixel allows for (i.e. lpbi->biClrUsed
* can be set to some value).
* If this is the case, return the appropriate value.
*/

DWORD dwClrUsed;

dwClrUsed = m_pBMI->bmiHeader.biClrUsed;
if (dwClrUsed != 0)
return (WORD)dwClrUsed;

/* Calculate the number of colors in the color table based on
* the number of bits per pixel for the DIB.
*/
wBitCount = m_pBMI->bmiHeader.biBitCount;

/* return number of colors based on bits per pixel */
switch (wBitCount)
{
case 1:
return 2;

case 4:
return 16;

case 8:
return 256;

default:
return 0;
}
}有些糊涂。
...全文
778 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiuxianshen 2010-06-20
  • 打赏
  • 举报
回复
biBitCount 单个像素所占直接数,例如,二值为1,灰度为8,RGB为24,RGBA为32
biClrUsed http://topic.csdn.net/u/20080606/20/ea8c6852-78fc-40e8-bcef-be78d37c6a42.html
Eleven 2010-06-20
  • 打赏
  • 举报
回复
参考MSDN上的BITMAPINFOHEADER结构体中的biBitCount成员的描述

19,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧