用GetDIBits获取8位图像素点怎么获取不了!!求大神给代码
贴代码如下,怎么遍历不了图片,而且发生断言:m_hobject!=NULL;然后还有严重的内存泄露。。求帮助
CBitmap m_bmp;
m_bmp.LoadBitmap("E:\bin\x64\2014_6_10_20_41_9_118.bmp");
BITMAP bm;
m_bmp.GetBitmap(&bm);
int nbyte = bm.bmBitsPixel/8;
BITMAPINFO bi;
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = bm.bmWidth;
bi.bmiHeader.biHeight = -bm.bmHeight;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 8; //位深为8
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * nbyte;
bi.bmiHeader.biXPelsPerMeter = 0;
bi.bmiHeader.biYPelsPerMeter = 0;
bi.bmiHeader.biClrUsed = 0;
bi.bmiHeader.biClrImportant = 0;
HDC hdc = ::GetDC(NULL);
BYTE* pBits = (BYTE*)new BYTE[bm.bmWidth * bm.bmHeight * nbyte];
HBITMAP hOldBmp = (HBITMAP)SelectObject(hdc,m_bmp);
BYTE picNum ;
int whiteFlag = 0;
::ZeroMemory(pBits, bm.bmWidth * bm.bmHeight * nbyte);
if (!::GetDIBits(hdc, m_bmp, 0, bm.bmHeight, pBits, &bi, DIB_RGB_COLORS))
{
delete pBits;
pBits = NULL;
}
myListNum.RemoveAll();
for(int i = 0;i <= 656;i++)
{
for(int j= 0;j <= 492;j++)
{
//bmWidthBytes:一行像素所占的字节数,一行像素的存储必须按word对齐,所以该值必须为2的倍数
BYTE r = pBits[i * nbyte + j * bm.bmWidthBytes + 2];
BYTE g = pBits[i * nbyte + j * bm.bmWidthBytes + 1];
BYTE b = pBits[i * nbyte + j * bm.bmWidthBytes + 0];
picNum = (int)((r*306 + g*601 + b*117)<<10);
COLORREF color = RGB(b, g, r);
outfileName << "color" << color << endl;
//myListNum.AddTail = -1;
}
}
delete pBits;
pBits = NULL;
}