如何理解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;
}
}有些糊涂。