如何获取24位bmp图片某个像素点的颜色信息?
我想获得的是RGB中B的灰度值
我的代码是这样的:
RGBQUAD cColor;
cColor=m_dib.GetPixel(x1, y1);
int a=cColor[10].rgbBlue;
所要的就是a
其中GetPixel(x,y)函数是这样的
RGBQUAD CDib::GetPixel(int x, int y)
{
// 颜色结构
RGBQUAD cColor;
// 根据每象素比特数得到此点的象素值
switch (m_lpBMIH->biBitCount)
{
case 1 :
if (1<<(7-x%8) & *(LPBYTE)(m_lpImage+GetPixelOffset(x, y)))
{
cColor.rgbBlue = 255;
cColor.rgbGreen = 255;
cColor.rgbRed = 255;
cColor.rgbReserved =0;
}
else
{
cColor.rgbBlue = 0;
cColor.rgbGreen = 0;
cColor.rgbRed = 0;
cColor.rgbReserved =0;
}
break;
case 4 :
{
int nIndex = (*(LPBYTE)(m_lpImage+GetPixelOffset(x, y)) &
(x%2 ? 0x0f : 0xf0)) >> (x%2 ? 0 : 4);
LPRGBQUAD pDibQuad = (LPRGBQUAD) (m_lpvColorTable) + nIndex;
cColor.rgbBlue = pDibQuad->rgbBlue;
cColor.rgbGreen = pDibQuad->rgbGreen;
cColor.rgbRed = pDibQuad->rgbRed;
cColor.rgbReserved =0;
}
break;
case 8 :
{
int nIndex = *(BYTE*)(m_lpImage+GetPixelOffset(x, y));
LPRGBQUAD pDibQuad = (LPRGBQUAD) (m_lpvColorTable) + nIndex;
cColor.rgbBlue = pDibQuad->rgbBlue;
cColor.rgbGreen = pDibQuad->rgbGreen;
cColor.rgbRed = pDibQuad->rgbRed;
cColor.rgbReserved =0;
}
break;
default:
int nIndex = *(BYTE*)(m_lpImage+GetPixelOffset(x, y));
cColor.rgbRed = m_lpImage[nIndex];
cColor.rgbGreen = m_lpImage[nIndex + 1];
cColor.rgbBlue = m_lpImage[nIndex + 2];
cColor.rgbReserved =0;
break;
}
这样做调试的时候a出了问题,得不到值
如何修改阿?