关于GetPixel的问题
CBitmap * CHQCtrlView::ChangeBitmap(HBITMAP hBitmap, int nType)
{
CBitmap * bm = CBitmap::FromHandle(hBitmap);
if(bm)
{
CDC * pDC = GetDC();
if(pDC)
{
CDC * pMemDC = new CDC;
if(pMemDC->CreateCompatibleDC(pDC))
{
CBitmap * OldBitmap = pMemDC->SelectObject(bm);
// 变灰
if(nType == 1)
{
BITMAP bmStruct;
bm->GetBitmap(&bmStruct);
for(int i=0;i<bmStruct.bmWidth;i++)
{
for(int j=0;j<bmStruct.bmHeight;j++)
{
COLORREF col = pMemDC->GetPixel(i,j); // 图片中的颜色为RGB(0,128,128)的地方取到的颜色居然为RGB(0,0,0)?
if(col != 0)
{
COLORREF tempcol = RGB(0,128,128);
if(col != RGB(0,128,128))
{
int gray = (((col>>16) & 0xff) * 299 + ((col>>8) & 0xff) * 587 + (col & 0xff) * 114 + 500)/1000;
pMemDC->SetPixel(i,j,RGB(gray,gray,gray));
}
}
}
}
}
// 离开
else if(nType == 2)
{
}
pMemDC->SelectObject(OldBitmap);
delete pMemDC;
ReleaseDC(pDC);
}
}
}
return bm;
}