Click here to Skip to main content
Licence 
First Posted 13 Apr 2006
Views 28,689
Downloads 1,137
Bookmarked 25 times

Alpha Blending Dialog Using GDI+

By | 13 Apr 2006 | Article
Alpha blending dialog using GDI+
Sample Image - gdiplusanphablend.jpg

Introduction

I've been using GDI+ for about a week now, and I must say it is a welcome upgrade.

This is a small example, it's very simple. I use a timer to change the alpha value of a dialog.

In OnPaint(), I use a buffer to improve the drawing of dialog:

  CPaintDC dc(this); 
  Graphics graphics(dc.m_hDC); 
  Bitmap bitmap(L"pic1.bmp");
  ImageAttributes imgatt;
  UINT width = bitmap.GetWidth();
  UINT height = bitmap.GetHeight(); 
  { // color matrix
   ColorMatrix colormatrix = {
    1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
    0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.0f, m_fAnpha, 0.0f,
    0.0f, 0.0f, 0.0f, 0.0f, 1.0f
   }; 
   imgatt.SetColorMatrix(&colormatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
   SolidBrush brush(Color(255, 255,255, 255));
   Bitmap bmBuffer(width, height); 
   Graphics* graphBuffer = Graphics::FromImage(&bmBuffer);
   graphBuffer->FillRectangle(&brush, Rect(0, 0, width, height));
   graphBuffer->DrawImage(
    &bitmap, 
    Rect(0, 0, width, height),
    0, 0,
    width,
    height,
    UnitPixel,
    &imgatt
   );
   graphics.DrawImage(&bmBuffer, 0, 0, width, height);
  }

And code in OnTimer():

 static float incr=0.01f;
 if (m_fAnpha >= 1.0f || m_fAnpha <= 0.01f)
 {
  incr = -incr;
 }
 m_fAnpha = m_fAnpha + incr;
 InvalidateRect(NULL, FALSE);

History

  • 14th April, 2006: Initial post

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

About the Author

Le Thanh Cong

Software Developer (Senior)

Vietnam Vietnam

Member

Study at Hanoi University of Technology 2001-2006

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMember functions, class pointers and namespaces PinmemberDr. Versaeg0:20 16 Sep '08  
GeneralAnpha -> Alpha PinmemberJörgen Sigvardsson4:32 14 Apr '06  
GeneralRe: Anpha -> Alpha PinmemberLe Thanh Cong20:16 16 Apr '06  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 14 Apr 2006
Article Copyright 2006 by Le Thanh Cong
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid