CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
我想使此bm显示为灰色。
bm.LoadBitmap(IDB_BITMAP1);
我想使此bm显示为灰色。
解决方案 »
- CFile.Read为什么读出的是乱码,急,求大侠帮忙。
- 请问如何使用ReadFile读取数据(100分)
- 如何程序实现屏蔽ie中的安装证书窗口
- 【】在MFC中如何将.BMP文件加为对话框的背景???
- 急求在AutoCAD以及在word里面的菜单上加入菜单项的问题
- 如何把一个 Handle转化为 Object
- 如何得到网页中有焦点的列表框("select")的对象?为什么IHTMLDocument2::get_activeElement没有反应?
- 我要学网络编程,向高手讨教,散分!
- 在CEdit控件,如何控制光标到指定的位置。。。。
- 当神经网络的输出层过多时怎么处理
- 请问哪有shepard插值算法
- MFC程序中如何加入一c程序编译连接!!
[in] Specifies a raster-operation code. These codes define how the color data for the source rectangle is to be combined with the color data for the destination rectangle to achieve the final color.
The following list shows some common raster operation codes. Value Description
BLACKNESS Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.)
CAPTUREBLT Windows 98/Me, Windows 2000/XP: Includes any windows that are layered on top of your window in the resulting image. By default, the image only contains your window. Note that this generally cannot be used for printing device contexts.
DSTINVERT Inverts the destination rectangle.
MERGECOPY Merges the colors of the source rectangle with the brush currently selected in hdcDest, by using the Boolean AND operator.
MERGEPAINT Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator.
NOMIRRORBITMAP Windows 98/Me, Windows 2000/XP: Prevents the bitmap from being mirrored.
NOTSRCCOPY Copies the inverted source rectangle to the destination.
NOTSRCERASE Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color.
PATCOPY Copies the brush currently selected in hdcDest, into the destination bitmap.
PATINVERT Combines the colors of the brush currently selected in hdcDest, with the colors of the destination rectangle by using the Boolean XOR operator.
PATPAINT Combines the colors of the brush currently selected in hdcDest, with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator.
SRCAND Combines the colors of the source and destination rectangles by using the Boolean AND operator.
SRCCOPY Copies the source rectangle directly to the destination rectangle.
SRCERASE Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator.
SRCINVERT Combines the colors of the source and destination rectangles by using the Boolean XOR operator.
SRCPAINT Combines the colors of the source and destination rectangles by using the Boolean OR operator.
WHITENESS Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.)
{ CDC dcMem;
dcMem.CreateCompatibleDC(NULL); CBitmap bmpMem;
bmpMem.CreateCompatibleBitmap(&dcMem, nWidth, nHeight);
CBitmap* pbmpMem = dcMem.SelectObject(&bmpMem); CDC dcBitmap;
dcBitmap.CreateCompatibleDC(NULL); CBitmap * pbmpOld = dcBitmap.SelectObject(&bitmap);
CBrush brushShadow;
CBrush brushHilight; dcMem.PatBlt(0, 0, nWidth, nHeight, WHITENESS);
dcBitmap.SetBkColor(GetSysColor(COLOR_BTNFACE));
dcMem.BitBlt(0, 0, nWidth, nHeight, &dcBitmap, nXSrc, nYSrc, SRCCOPY);
dcBitmap.SetBkColor(GetSysColor(COLOR_BTNHILIGHT));
dcMem.BitBlt(0, 0, nWidth, nHeight, &dcBitmap, nXSrc, nYSrc, SRCPAINT);
dcBitmap.FillSolidRect(0, 0, nWidth, nHeight, GetSysColor((IsNewShell()) ? COLOR_3DFACE : COLOR_MENU));
dcBitmap.SetBkColor(RGB(0, 0, 0));
dcBitmap.SetTextColor(RGB(255, 255, 255));
brushHilight.CreateSolidBrush(GetSysColor(COLOR_BTNHILIGHT));
brushShadow.CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
CBrush * pbrushOld = dcBitmap.SelectObject(&brushHilight);
dcBitmap.BitBlt(0, 0, nWidth, nHeight, &dcMem, 0, 0, 0x00E20746L);
pDC->BitBlt(nXDest+1,nYDest+1,nWidth, nHeight, &dcBitmap,0,0,SRCCOPY);
dcBitmap.BitBlt(1, 1, nWidth, nHeight, &dcMem, 0, 0, 0x00E20746L);
dcBitmap.SelectObject(&brushShadow);
dcBitmap.BitBlt(0, 0, nWidth, nHeight, &dcMem, 0, 0, 0x00E20746L);
pDC->BitBlt(nXDest, nYDest, nWidth, nHeight, &dcBitmap, 0, 0, SRCCOPY); dcMem.SelectObject(pbmpMem);
dcBitmap.SelectObject(pbrushOld);
dcBitmap.SelectObject(pbmpOld);
dcMem.DeleteDC();
dcBitmap.DeleteDC();
bmpMem.DeleteObject();
}
{
// get the bitmap's size and colour information
BITMAP bm;
if (NULL == hBitmap || ::GetObject(hBitmap, sizeof(BITMAP), &bm) == 0)
return 0; // create a DIBSection copy of the original bitmap
HBITMAP hDib = (HBITMAP)::CopyImage(hBitmap, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG | LR_CREATEDIBSECTION);
if (bm.bmBitsPixel < 16)
{ // bitmap has a colour table, so we modify the colour table
CDC memDC;
memDC.CreateCompatibleDC(pDC);
int SavedMemDC = memDC.SaveDC();
memDC.SelectObject(hDib);
int nColours = 1 << bm.bmBitsPixel;
RGBQUAD pal[256];
// Get the colour table
::GetDIBColorTable(memDC.m_hDC, 0, nColours, pal);
// modify the colour table
for (int x = 0; x < nColours; x++)
{
BYTE nGray = (BYTE)Gray(pal[x].rgbRed, pal[x].rgbGreen, pal[x].rgbBlue);
pal[x].rgbRed = nGray;
pal[x].rgbGreen = nGray;
pal[x].rgbBlue = nGray;
}
// set the modified colour tab to the DIBSection bitmap
::SetDIBColorTable(memDC.m_hDC, 0, nColours, pal);
memDC.RestoreDC(SavedMemDC);
memDC.DeleteDC();
return hDib;
} else
{ // the bitmap does not have a colour table, so we modify the bitmap bits directly
int Size = bm.bmHeight * bm.bmWidth;
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biHeight = bm.bmHeight;
bmi.bmiHeader.biWidth = bm.bmWidth;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = bm.bmBitsPixel;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = ((bm.bmWidth * bm.bmBitsPixel + 31) & (~31)) / 8 * bm.bmHeight;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
// Get the bitmaps data bits
BYTE *pBits = new BYTE[bmi.bmiHeader.biSizeImage];
VERIFY (::GetDIBits(pDC->m_hDC, hDib, 0, bm.bmHeight, pBits, &bmi, DIB_RGB_COLORS)); if (bm.bmBitsPixel == 32)
{
DWORD *dst=(DWORD *)pBits;
while (Size--)
{
int nGray = Gray(GetBValue(*dst), GetGValue(*dst), GetRValue(*dst));
*dst = (DWORD)RGB(nGray, nGray, nGray);
dst++;
}
}
else if (bm.bmBitsPixel == 24)
{
BYTE *dst=(BYTE*)pBits;
for (int dh = 0; dh < bm.bmHeight; dh++)
{
for (int dw = 0; dw < bm.bmWidth; dw++)
{
int nGray = Gray(dst[2], dst[1], dst[0]);
dst[0]=(BYTE)nGray;
dst[1]=(BYTE)nGray;
dst[2]=(BYTE)nGray;
dst += 3;
}
// each row is DWORD aligned, so when we reach the end of a row, we
// have to realign the pointer to point to the start of the next row
int pos = (int)dst - (int)pBits;
int rem = pos % 4;
if (rem)
dst += 4 - rem;
}
}
else if (bm.bmBitsPixel == 16)
{
WORD *dst=(WORD*)pBits;
while (Size--)
{
BYTE b = (BYTE)((*dst)&(0x1F));
BYTE g = (BYTE)(((*dst)>>5)&(0x1F));
BYTE r = (BYTE)(((*dst)>>10)&(0x1F));
int nGray = Gray(r, g, b);
*dst = ((WORD)(((BYTE)(nGray)|((WORD)((BYTE)(nGray))<<5))|(((DWORD)(BYTE)(nGray))<<10)));
dst++;
}
}
// set the modified bitmap data bits to the DIBSection
::SetDIBits(pDC->m_hDC, hDib, 0, bm.bmHeight, pBits, &bmi, DIB_RGB_COLORS);
delete[] pBits;
return hDib;
}
}