Transparent DC class library
Download
source file 130K
Introduction
The library class file is lib\TransparentDC.h inside zipped source file.
The class contains two public static functions, which can blt dc to dc transparently.
They are target to Win32, so you can use them in both Win32 and MFC.
Signatures:
- BOOL BitBlt( HDC hdcDes,int iDesX,int iDesY,
HDC hdcSrc,int iSrcX,int iSrcY,int iSrcW,int iSrcH,
COLORREF clrTransparent);
- BOOL StretchBlt(HDC hdcDes,int iDesX,int iDesY,int iDesW,int iDesH,
HDC hdcSrc,int iSrcX,int iSrcY,int iSrcW,int iSrcH,
COLORREF clrTransparent);
The 2 functions are similar to Win32 related functions, please reference Visual C++ documents for more.
Parameters
- iDesX,int iDesY,int iDesW,int iDesH
Destination DC's left, top positions, width and height respectively.
- iSrcX,int iSrcY,int iSrcW,int iSrcH
Source DC's left, top positions, width and height respectively.
- clrTransparent
Transparence color
Performances
- They are slower than un-transparent functions
So please use in slow cases, such as printing, displaying a few of graphics.
- Valid for common map-mode
But StretchBlt() doesn't work for MM_HIMETRIC, it may be fixed later if I have time.
Sample
This is a MFC sample.
There is only one memory DC inside code, whose bitmap is loaded from resource by LoadBitmap() function.
Colorful big rectangle in the middle of Fig above
The rectangle is paint area for testing both normal DC and transparent DC functions.
Its appearance (color) can be changed by right combo-box: Background, so you can see transparence easily.
Top row in the colorful big rectangle
The row contains 2 blt results by
normal DC from memory DC.
Left one is by BitBlt(), right one is by StretchBlt().
Resource bitmap is in size 32x32 as left one.
Bottom row in the colorful big rectangle
The row contains 2 blt results by
transparent DC from memory DC.
Left one is by BitBlt(), right one is by StretchBlt().
You can see white color is transparence from right one clearly.
Combo-boxes at right side
- MapMode
Used for changing MapMode of DCs by SetMapMode() function.
- Background
Used for changing background of paint area.
- Transparent color
Used for selecting transparent color of transparent DC.
Result so far:
Transparent StretchBlt() and BitBlt() have benn further modified and implemented in our product: Paper Label Maker - a topmost software in the world, which allows any more transparent colors in theory.
In practice, Paper Label Maker sets the number of transparent colors as "only" 30, it is also printable rather than just viewable in screen!
Unfortuanately, I can not offer source code of advanced one for you, why don't you modify it yourself?