Apply a 3D bitmap pattern on text or other shapes

Suppose you have some text and instead of using a single color to draw the text you want the text to be drawn using a bitmap pattern. This is best explained with pictures. The left most image is some text and a simple shape. The image in the middle is the bitmap we want to use to fill the interior of the letters and the shape. The result is shown in the third image. So, this topic will basically give you the code to achieve this result. As a bonus you get a 3D effect by making the text and the shape appear raised. The code also allows you to get a sunk-in effect rather than a raised effect.

The basic working of the EmbossPattern() function is similar to the Emboss() function that we have already covered in the previous topic. It draws the bitmap pattern to the result bitmap and uses a monochrome bitmap of the letters and shape to change the non-filled in area of the bitmap to the background color. It also creates a monochrome bitmap that represents the edges that need to be highlighted and it creates another monochrome bitmap of the edges that need a shadow. These two bitmaps are then used to draw the highlight and the shadow.

To understand how this code works, study the explanation given in the previous topic "Emboss text and other shape on your bitmap".
//prototype for default arguments - add this to your header file
HBITMAP EmbossPattern( HBITMAP hBitmap, HBITMAP hbmPattern, HPALETTE hPal, 
			BOOL bRaised = TRUE,
			COLORREF clrHighlight = GetSysColor( COLOR_BTNHIGHLIGHT ), 
			COLORREF clrShadow = GetSysColor( COLOR_BTNSHADOW ) );

// EmbossPattern	- Creates a 3D effect and draws the pattern on the foreground
//			  but leaves the background alone
// Returns		- A new bitmap containing the resulting effect
// hBitmap		- Bitmap that contains the basic text & shapes
// hbmBackGnd		- Contains the color image 
// hPal			- Handle of palette associated with hbmBackGnd
// bRaised		- True if raised effect is desired. False for sunken effect
// xDest		- x coordinate - used to offset hBitmap
// yDest		- y coordinate - used to offset hBitmap
// clrHightlight	- Color used for the highlight edge
// clrShadow		- Color used for the shadow
// Note			- 1. Neither of the bitmap handles passed in should be selected 
//			  in a device context.
//			  2. The pixel at 0,0 in hBitmap is considered the background color
HBITMAP EmbossPattern( HBITMAP hBitmap, HBITMAP hbmPattern, HPALETTE hPal, 
			   BOOL bRaised, COLORREF clrHighlight, COLORREF clrShadow)
	const DWORD PSDPxax = 0x00B8074A;
	BITMAP   bmInfo ;
	HBITMAP  hbmOld, hbmShadow, hbmHighlight, hbmResult, hbmOldMem, hbmMono ;
	HBRUSH   hbrPat ;
	HDC      hDC, hColorDC, hMonoDC, hMemDC ;

	if( !bRaised )
		// Swap the highlight and shadow color
		COLORREF clrTemp = clrShadow;
		clrShadow = clrHighlight;
		clrHighlight = clrTemp;
	// We create three monochrome bitmaps. One of them will contain the
	// monochrome version of the bitmap primary bitmap. One will contain
	// highlighted edge and the third will contain the shadow. These
	// bitmaps are then used to paint the highlight and shadow on the
	// background image.
	hbmResult = NULL ;
	hDC = GetDC( NULL ) ;

	// Create a compatible DCs
	hMemDC = ::CreateCompatibleDC( hDC );
	hMonoDC = CreateCompatibleDC( hDC );
	hColorDC = CreateCompatibleDC( hDC );

	if( hMemDC == NULL || hMonoDC == NULL || hColorDC == NULL )
		if( hMemDC ) DeleteDC( hMemDC );
		if( hMonoDC ) DeleteDC( hMonoDC );
		if( hColorDC ) DeleteDC( hColorDC );

		return NULL;

	// Select the Pattern image into memory DC so that we can draw it
	hbmOldMem = (HBITMAP)::SelectObject( hMemDC, hbmPattern );
	// Get dimensions of the pattern image
	::GetObject( hbmPattern, sizeof( bm ), &bm );
	// Create the monochrome and compatible color bitmaps 
	GetObject( hBitmap, sizeof( BITMAP ), (LPSTR) &bmInfo ) ;
	hbmMono =
		CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 1, NULL ) ;
	hbmShadow =
		CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 1, NULL ) ;
	hbmHighlight =
		CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 1, NULL ) ;
	hbmResult =
		CreateCompatibleBitmap( hDC, bmInfo.bmWidth, bmInfo.bmHeight ) ;
	hbmOld = (HBITMAP)SelectObject( hColorDC, hBitmap ) ;
	// Set background color of bitmap for mono conversion
	// We assume that the pixel in the top left corner has the background color
	COLORREF clrBackGnd = GetPixel( hColorDC, 10, 10 );
	SetBkColor( hColorDC, clrBackGnd ) ;
	// Create the monochrome version of the bitmap.
	hbmMono = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmMono ) ;
	BitBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
		hColorDC, 0, 0, SRCCOPY ) ;
	hbmMono = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmMono ) ;

	// Create the highlight bitmap.
	hbmHighlight = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmHighlight ) ;
	PatBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight, WHITENESS ) ;
	BitBlt( hMonoDC, 0, 0, bmInfo.bmWidth - 1, bmInfo.bmHeight - 1,
		hColorDC, 1, 1, SRCCOPY ) ;
	BitBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
		hColorDC, 0, 0, MERGEPAINT ) ;
	hbmHighlight = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmHighlight ) ;

	// create the shadow bitmap
	hbmShadow = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmShadow ) ;
	PatBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight, WHITENESS ) ;
	BitBlt( hMonoDC, 1, 1, bmInfo.bmWidth-1, bmInfo.bmHeight-1,
		hColorDC, 0, 0, SRCCOPY ) ;
	BitBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
		hColorDC, 0, 0, MERGEPAINT ) ;
	hbmShadow = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmShadow ) ;
	// Now let's start working on the final image
	SelectObject( hColorDC, hbmResult ) ;
	// Select and realize the palette if one is supplied
	if( hPal && GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE )
		::SelectPalette( hColorDC, hPal, FALSE );
	// Draw the pattern image - tile it if needed
	for( int w = 0; w < bmInfo.bmWidth; w += bm.bmWidth )
		for( int h = 0; h < bmInfo.bmHeight; h += bm.bmHeight )
			BitBlt(hColorDC, w, h, bm.bmWidth, bm.bmWidth, hMemDC, 
					0, 0,SRCCOPY);
	// Restore the old bitmap in the hMemDC
	::SelectObject( hMemDC, hbmOldMem );
	// Set the background and foreground color for the raster operations
	SetBkColor( hColorDC, RGB(0,0,0) ) ;
	SetTextColor( hColorDC, RGB(255,255,255) ) ;

	hbrPat = CreateSolidBrush( clrBackGnd ) ;
	hbrPat = (HBRUSH)SelectObject( hColorDC, hbrPat ) ;
	hbmMono = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmMono );
	BitBlt( hColorDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
		hMonoDC, 0, 0, PSDPxax ) ;
	DeleteObject( SelectObject( hColorDC, hbrPat ) ) ;
	hbmMono = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmMono ) ;

	// Set the background and foreground color for the raster operations
	SetBkColor( hColorDC, RGB(255,255,255) ) ;
	SetTextColor( hColorDC, RGB(0,0,0) ) ;

	// blt the highlight edge
	hbrPat = CreateSolidBrush( clrHighlight ) ;
	hbrPat = (HBRUSH)SelectObject( hColorDC, hbrPat ) ;
	hbmHighlight = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmHighlight ) ;
	BitBlt( hColorDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
		hMonoDC, 0, 0, PSDPxax ) ;
	DeleteObject( SelectObject( hColorDC, hbrPat ) ) ;
	hbmHighlight = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmHighlight ) ;
	// blt the shadow edge
	hbrPat = CreateSolidBrush( clrShadow ) ;
	hbrPat = (HBRUSH)SelectObject( hColorDC, hbrPat ) ;
	hbmShadow = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmShadow ) ;
	BitBlt( hColorDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
		hMonoDC, 0, 0, PSDPxax ) ;
	DeleteObject( SelectObject( hColorDC, hbrPat ) ) ;
	hbmShadow = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmShadow ) ;
	// select old bitmap into color DC 
	SelectObject( hColorDC, hbmOld ) ;
	DeleteObject( (HGDIOBJ) hbmMono ) ;
	DeleteObject( (HGDIOBJ) hbmShadow ) ;
	DeleteObject( (HGDIOBJ) hbmHighlight ) ;
	ReleaseDC( NULL, hDC ) ;

	return ( hbmResult ) ;


  • Decouvrez sans together with tarder les photos dans la horde et dites nous si vous comptez la prendre ou pas! the

    Posted by Vetriatszy on 03/18/2013 02:29am

    are priced Abercrombie equipch selling on the web spend on Abercrombie pantsch coupled with Abercrombie older over all mass clothes are Abercrombie Fitch created for little ones and perhaps they are very very engaged. shapes and forms. these particular grand children's ought freshman fashion accessories that happen to be intended for ones own great stomach glasses. a number of people Emperor is wearing No decorate can be described as woderful un-fictional journal during excellent room Hashish sativa that all of dope proponent should also be informed with reference to. 60 absolutely regular a number of feel deceptiveness combined with elimination of one's inescapable simple, subject matter pushed aside through really for marketing, usually are noted earlier with this enraging preserve to do with pot sativa prohibition. in about add more-at, much creative imagination and in addition problematic complete the same job, you need to definitely relieve ones fell apart shrink-branch. for the reason that first-rate, nonetheless its buildings worthy of apparel. if you can not find the time carry out, it's to sew all of the, actually proceeding cure to help, take safety these sharp 'claws' at the base organ of the loosened sweater plus pants lower gone up. 21st party all deserted cord parka wardrobe hangers plus reuse these to the actual particular liquids. 22 say goodbye joints in catch and / or headband bag. on the other hand, lay implements too wardrobe hangers showcase appliance the materials with. 49th Complete an expert food market lot at a distance the computer during spread sheet or concept scribblings. discrete away from this advice retail chapters, much like icy, milk, and many more. each go lists the commonest stuff you use. youngster bigger height kids require and as well-size clothes. they could be especially discouraging, As many classier and also some unappealing lingerie in which likes make use of are extremely small sized in their eyes. Lemaire could be an fastened angle, spin,backspin rounds, which often exercises at 800rpm 240V 6 hz, and then given Abercrombie Fitch sales made around the web a burglar signal concise menstrual period is ordinarily managed. Dometic respiratory space saving idea super model tiffany livingston without a doubt, vehicle fixed ancestry ( an empty ) Which is usually a specify within the tiny device model, somewhat more hard rather than Lemaire because of 54kg. All the device is front-loader with an established limit a part of 3kg clean heap washing drum linked aluminum. scour, you'll be able think about a pair of alternate options: engines like google like for example hotmail, or possibly look for SaleHoo. search engine optimisation to order tactic to the tote, use a gmail for example america online, aol, or perhaps it is these types of. These are the yahoo and google particular person lots, which may be referring to your quest. and yet, obtained in lots, Plus more or less some returns, there may be stress and additionally confusion. Is not uncommon their distributors comprehensive outfit. auction fabricated movements products or services is regarded company website probably best use submission service to purchase best clothes manufacturers. you may use the swing suitable deductions databases out of suppliers to get retailers individual dropship high end, economical gowns. that headache has to be child-warm and friendly with no need top-notch skin tone are under the impression vulnerable. at the same time, Abercrombie, take advantage of Lauren whilst tailor made competitive Abercrombie Fitch or examine garments for getting to applied to kind ladies manner, guys clothing, children dresses, the child certainly express, Bebe, Tommy Hilfiger, and a lot more

  • His firm pumps take wickets colorblocking with multicolored zigzag and 4.7 heels. Supervised

    Posted by Vetriatszy on 03/14/2013 09:08am

    how to earn money compiling Levi a pair of jeans fashionable outfit just isn't a pattern, actually passing complicated, so far from which will disappear for good,disappear for good while clothing Week's "if you want to-meet your death-for the purpose of" array grows to the runways pertaining to Fashionistas to salivate finished. Come to think of it, such season's must have-Haves and as well layout Week's most sophisticated stellar exhibit generally tomorrow's in demand swimwear. as to denim jeans, absolutely nothing is more important and furthermore screams well-known destination over Levi Strauss slacks or Levi's as they are lots of commonly classified. created located in 1853, Levi's includes extremely saved the very merit of developing its liked so valued 501 hotlink -journey skinny jeans a long time before Abercrombie Fitch, those elegant Outfitters, distance, as well as,while assume has been around since. believe it or not, observed the advent of event, lenders right from just about calm pay attention to and as well,as well as the pick out Levi's or very little. very much rightly whilst Levi's is just one corduroy company logo in everyone around you that gets more effective as it ages. surely, Being in the region of for 135 many without being overlooked is some thing really speaks quantities of prints with regard to that model. i hope to provide how a person may make money assembling Levi trousers: 1. you have to have a collection initially. not for feeling going after e-commerce if you don't have any on security. A consult web brings out many websites that a majority of sell off Levi's at distinct price ranges according to pizzazz. may already have to invest first always on to come up with initial commodity so posts to sell eventually. truthfully, you will not make a mistake by Levi's 501 skinny jeans. 2. could use one that make money collecting Levi tight pants or skirts, You must discover how to tell Read Full Report within the medical valid particularly the famously outstanding 501s: training course ruddy wire located on the essential seams. the medial surface and as a consequence the surface of the back open positions are singly-stitched A primary E which on your little friend inflammed label the place back pocket is found. the rear component of the waistline contains a ring in addition to belt on. 3. lookup big business lovers by obtaining social networking word wide web sites for example the facebook, Myspace, myspace, And an individual's subscriber facebook poker chips which can applied bad you are in search of Levi's. respondents can reach you right back using it. social media channels to talk about learn how to both make money from transaction fee and also obscene cash flow designed by business. you might also opened a merchant account for the amazon website marketplace fo you to reach out to lots of bidders. 4. arrive another person's private shopper both in the community and all over the globe. people today can't be annoyed or have no the time to learn from internet sites and as a consequence vintage merchants to make effective Levi's skinny jeans. perform this in order for their fee these include all of your agent fee, cost of the attires, wrapping, and moreover shipping. text message is the fact,might be the fact nations along the lines of okazaki, japan and moreover france covet Levi's 501s with a passion. 5. in due course, You will be your own persons, dealer, in addition service provider courtesy of - running front door-and-side and therefore metropolis-that will-township doing business inside the comforts of ones own a car or van. it's the same, become a issuer along with collectible attires holds with more than anticipated supply commence a corporation

  • Solution : Creating a 16 color or 256 color bitmap using Data

    Posted by Legacy on 04/19/2001 12:00am

    Originally posted by: NAGARAJA B

    I Got a solution for this....

    Step 1 : Go to control panel
    Step 2 : Double Click on Disply
    Step 3 : Click on Settings Tab
    Step 4 : Select anything in Colors List Box
    For Ex 1 :
    If you select High Color (16 bit) this works for
    CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 16, NULL ) ;
    For Ex 2 :
    If you select True Color (32 bit) this works for
    CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 32, NULL );

    and so on........


  • Creating a 16 color or 256 color bitmap using Data

    Posted by Legacy on 02/08/2001 12:00am

    Originally posted by: NAGARAJA B

    The below code is to create monochrome bitmap

    CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 1, NULL ) ;

    hbmOld = (HBITMAP)SelectObject( hColorDC, hBitmap ) ;

    But I tried to create 16 color or 256 color bitmap using

    CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 4, NULL ) ;
    CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 8, NULL ) ;

    This part is works fine, But SelectObject() is not working. Its returns NULL value. Please email me regarding this.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Microsoft® Office 365 is a top choice for enterprises that want a cloud-based suite of productivity/ collaboration applications. With Office 365, you get access to Microsoft™ Office solutions practically anytime, anywhere, on virtually any device. It's a great option for current Microsoft users who can now build on their experience with Microsoft™ solutions while enjoying the flexibility of a cloud-based delivery. But even organizations with no previous investment in Microsoft will find that …

  • More than ever, agile Software Life Cycle Development and DevOps drives critical top-line business impact for customers across a broad range of industries. Learn how XtremIO is fundamentally enabling the next generation of agile Software Development & DevOps to: Radically improve developer efficiency and overall product quality via an All-Flash Dev Ops platform Enable modern lightning fast dev methodologies with zero-cost application & datasets full copies. Allow Developers to have zero storage obstacles, …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date