当前位置:我的异常网» VC/MFC » 怎么将24位色BMP图片改为单色或16色?
怎么将24位色BMP图片改为单色或16色?(2)
www.myexceptions.net 网友分享于:2013-01-10 浏览:432次
GetClientRect(hWnd,&rc);
Width = rc.right-rc.left;
Height = rc.bottom-rc.top;
}
hDC = GetDC(hWnd); //获取指定的DC
hMemDC = CreateCompatibleDC(hDC);
hBitmap= CreateCompatibleBitmap(hDC, Width, Height);
hTmpBmp= CreateCompatibleBitmap(hDC, 8, 8);
pBmInfoMem = (LPBITMAPINFO)GlobalAlloc(GHND, sizeof(BITMAPINFO)+256*sizeof(RGBQUAD));
pBmInfo = (LPBITMAPINFO)GlobalLock(pBmInfoMem);
SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC,0,0,Width,Height,hDC,0,0,SRCCOPY);
SelectObject(hMemDC, hTmpBmp);
ZeroMemory(pBmInfo, sizeof(BITMAPINFO));
pBmInfo-> bmiHeader.biSize = (DWORD)sizeof(BITMAPINFOHEADER);
pBmInfo-> bmiHeader.biWidth = Width;
pBmInfo-> bmiHeader.biHeight = Height;
pBmInfo-> bmiHeader.biPlanes = 1;
pBmInfo-> bmiHeader.biBitCount = (WORD)GetDeviceCaps(hDC, BITSPIXEL);
pBmInfo-> bmiHeader.biCompression = BI_RGB;
//pBmInfo-> bmiHeader.biCompression = BI_RLE8;
GetDIBits(hDC, hBitmap, 0,Height, NULL, pBmInfo, DIB_RGB_COLORS);
文章评论