Click here to Skip to main content
Click here to Skip to main content

Transparent DC class library

, 14 Jun 2006
Rate this:
Please Sign up or sign in to vote.
A class library of transparent DC

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: 

  1. BOOL BitBlt( HDC hdcDes,int iDesX,int iDesY,
    HDC hdcSrc,int iSrcX,int iSrcY,int iSrcW,int iSrcH,
    COLORREF clrTransparent);
  2. 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
  1. MapMode
    Used for changing MapMode of DCs by SetMapMode() function.
  2. Background
    Used for changing background of paint area.
  3. 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?
  



License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

includeh10
Web Developer
Australia Australia

Please visit our Download Home to obtain many interesting software for free ...



Comments and Discussions

 
GeneralNo comments! [modified] PinmemberCoreyCooper18-Jun-07 9:58 
GeneralDownload Link doesnt work PinmemberKarstenK15-Jun-06 0:35 
GeneralRe: Download Link doesnt work Pinmemberincludeh1015-Jun-06 2:31 
GeneralRe: Download Link doesnt work PinmemberKarstenK15-Jun-06 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 14 Jun 2006
Article Copyright 2006 by includeh10
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid