Gray and Dithered Bitmap Functions
Gray Bitmap Functions
MFC provides two functions for giving a bitmap the appearance of a disabled control.
Name | Description |
---|---|
AfxDrawGrayBitmap | Draws a gray version of a bitmap. |
AfxGetGrayBitmap | Copies a gray version of a bitmap. |
Dithered Bitmap Functions
MFC also provides two functions for replacing a bitmap's background with a dithered pattern.
Name | Description |
---|---|
AfxDrawDitheredBitmap | Draws a bitmap with a dithered background. |
AfxGetDitheredBitmap | Copies a bitmap with a dithered background. |
AfxDrawGrayBitmap
Draws a gray version of a bitmap.
void AFXAPI AfxDrawGrayBitmap(
CDC* pDC,
int x,
int y,
const CBitmap& rSrc,
COLORREF crBackground);
Parameters
pDC
Points to the destination DC.
x
The destination x-coordinate.
y
The destination y-coordinate.
rSrc
The source bitmap.
crBackground
The new background color (typically gray, such as COLOR_MENU).
Remarks
A bitmap drawn with AfxDrawGrayBitmap
will have the appearance of a disabled control.
Example
void CDCView::DrawGrayBitmap(CDC* pDC)
{
CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
AfxDrawGrayBitmap(pDC, 10, 50, bm, GetSysColor(COLOR_MENU));
}
Requirements
Header: afxwin.h
AfxGetGrayBitmap
Copies a gray version of a bitmap.
void AFXAPI AfxGetGrayBitmap(
const CBitmap& rSrc,
CBitmap* pDest,
COLORREF crBackground);
Parameters
rSrc
The source bitmap.
pDest
The destination bitmap.
crBackground
The new background color (typically gray, such as COLOR_MENU).
Remarks
A bitmap copied with AfxGetGrayBitmap
will have the appearance of a disabled control.
Example
CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
CBitmap bmGray;
AfxGetGrayBitmap(bm, &bmGray, GetSysColor(COLOR_MENU));
Requirements
Header: afxwin.h
AfxDrawDitheredBitmap
Draws a bitmap, replacing its background with a dithered (checker) pattern.
void AFXAPI AfxDrawDitheredBitmap(
CDC* pDC,
int x,
int y,
const CBitmap& rSrc,
COLORREF cr1 ,
COLORREF cr2);
Parameters
pDC
Points to the destination DC.
x
The destination x-coordinate.
y
The destination y-coordinate.
rSrc
The source bitmap.
cr1
One of the two dither colors, typically white.
cr2
The other dither color, typically light gray (COLOR_MENU).
Remarks
The source bitmap is drawn on the destination DC with a two-color (cr1 and cr2) checkered pattern replacing the bitmap's background. The background of the source bitmap is defined as its white pixels and all pixels matching the color of the pixel in the upper-left corner of the bitmap.
Example
void CDCView::DrawDitheredBitmap(CDC* pDC)
{
CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
AfxDrawDitheredBitmap(pDC, 10, 50, bm, RGB(255, 255, 255),
GetSysColor(COLOR_BTNFACE));
}
Requirements
Header: afxwin.h
AfxGetDitheredBitmap
Copies a bitmap, replacing its background with a dithered (checker) pattern.
void AFXAPI AfxGetDitheredBitmap(
const CBitmap& rSrc,
CBitmap* pDest,
COLORREF cr1 ,
COLORREF cr2);
Parameters
rSrc
The source bitmap.
pDest
The destination bitmap.
cr1
One of the two dither colors, typically white.
cr2
The other dither color, typically light gray (COLOR_MENU).
Remarks
The source bitmap is copied to the destination bitmap with a two-color (cr1 and cr2) checkered pattern replacing the source bitmap's background. The background of the source bitmap is defined as its white pixels and all pixels matching the color of the pixel in the upper-left corner of the bitmap.
Example
CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
CBitmap bmDith;
AfxGetDitheredBitmap(bm, &bmDith, RGB(255, 255, 255),
GetSysColor(COLOR_BTNFACE));
Requirements
Header: afxwin.h