![]() |
Multimedia »
General Graphics »
General
Intermediate
License: The Code Project Open License (CPOL)
CContourBitmap - A Region CreatorBy Wolfgang BuschA bitmap class with a "brute-force" region creator |
VC6, VC7, VC7.1, Windows, MFC, VS.NET2003, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
A few weeks ago I was looking for a way to create irregularly shaped windows from a bitmap with a user defined transparent color. The MFC samples, that I found so far, have their problems with enclosed transparent regions. So I decided to come up with my own solution.
CContourBitmap uses a very simple but failsafe "brute-force" algorithm to calculate
a region from a bitmap with a user defined transparent color. It starts with the rectangular region given by
the bitmap's dimensions and then scans the bitmap row by row. Every "transparent" row section, that
is found, is subtracted from the bitmap's region, giving a new bitmap's region.
Below there is a (reduced) screenshot of the demo application's main window. (Well, the copyright line
has been added later.) But as you can see, CContourBitmap has no problems with convex or
concave shapes or fully enclosed transparent regions.

CContourBitmap offers two different methods to calculate a region from a bitmap:
HRGN CContourBitmap::CreateRegion(COLORREF colorTransp=CLR_DEFAULT)Use this function to explicitly specify the transparent color. (Or use the default color, that is the color of the topleft pixel.)
HRGN CContourBitmap::CreateRegion(CPoint pntTransparentColor)Use this function to extract the transparent color from any pixel within the image. (If the pixel is outside of the bitmap, the return value is NULL.)
Apart from these methods, there are two other helpful functions to ease bitmap handling:
CSize CContourBitmap::GetSize()Returns the dimensions of the bitmap.
BOOL CContourBitmap::Paint(CDC* pDC, int nXDest=0, int nYDest=0)Copies the bitmap with an optional offset to the given device context.
CContourBitmap is derived from CBitmap. It adds no attributes to the base
class. Thus, casting a CBitmap to CContourBitmap is save.
Specifying a 24 bit transparent color on a Windows desktop with 16 bit color depth may not work correctly. Needs a conversion from the 24 bit color space to the 16 bit color space.
The Pink Panther TM & (C) 1964 by Metro-Goldwyn-Mayer Studios, Inc.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Jul 2004 Editor: Nishant Sivakumar |
Copyright 2004 by Wolfgang Busch Everything else Copyright © CodeProject, 1999-2009 Web13 | Advertise on the Code Project |