【求助】24位位图灰度化出错,帮看下哪错了
//图像宽320,高216LPBYTE lprgbBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbmhrgb->biSizeImage);//为彩色图像开辟内存
GetDIBits(pDC->m_hDC, hbmp, 0, 216, lprgbBits, pbmirgb, DIB_RGB_COLORS);//从图像句柄hbmp获得彩色图像的rgb数据并存入内存lprgbBits中
LPBYTE lpgrayBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, 216*320);//为灰度图开辟内存
int i,j,k;
LPBYTE lprbits,lpgbits,lpbbits,lpgray;
for(i=0;i<216;i++)
{
for(j=0;j<320;j++)
{
k=(215-i)*320+j;
lprbits=lprgbBits+3*k;
lpgbits=lprbits+1;
lpbbits=lpgbits+1;
lpgray=lpgrayBits+k;
*lpgray=(BYTE)((*lprbits)*0.299+(*lpgbits)*0.587+(*lpbbits)*0.114);
SetPixel(pDC->m_hDC,j,i,RGB(*(lpgrayBits+k),*(lpgrayBits+k),*(lpgrayBits+k)));
}
}
测试图.rar
(90.41 KB)