Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / C#

Per Pixel Alpha Blend in C#

Rate me:
Please Sign up or sign in to vote.
4.72/5 (73 votes)
3 Jun 20041 min read 600.9K   19.4K   191   115
Demonstrates how to create per pixel alpha blending Windows

Preview of the per pixel alpha blend effect

Preview of the per pixel alpha blend effect

Introduction

This is a port of my other article from C++/MFC to C#/Windows Forms. The concept of creating a per-pixel-alpha blending window remains the same, the GDI function UpdateLayeredWindow.

What Changed

  • Image loading is handled by GDI+ classes (System.Drawing namespace)
  • No need to pre-multiply the rgb channels with the alpha channel
  • No more support for PSP files. PNG file are the best choice

Usage

To use this code, you need to include PerPixelAlphaForm.cs file in your project, create a class that inherits from PerPixelAlphaForm, load a bitmap using System.DrawingImage.FromFile static method and then call the PerPixelAlphaForm.SetBitmap method.

The example source code is inside the main.cs file. In the source code, you will also find new ways of doing old things, like, handling dropped files from Windows Explorer.

 

Installing & Building

  1. Download and extract the source code of this article.
  2. To build, run the build.bat file from command prompt.
  3. Now, run the bin\main.exe and enjoy!

Changelog

31st May, 2004

  • Fix clipping problems by creating the form without borders.
  • Move PerPixelAlphaForm class to PerPixelAlphaForm.cs file.

12th February, 2002

  • Initial version

Do you have any question or comment? Please leave a note below.

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.


Written By
Web Developer
Portugal Portugal
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionClick event Pin
mybigfatcatNL10-Aug-12 7:37
mybigfatcatNL10-Aug-12 7:37 
GeneralMy vote of 4 Pin
Yawness13-May-12 20:51
Yawness13-May-12 20:51 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey18-Feb-12 3:29
professionalManoj Kumar Choubey18-Feb-12 3:29 
QuestionDrawing other stuff on? Pin
Rohit Dubey from Hyderabad22-Jan-12 20:10
Rohit Dubey from Hyderabad22-Jan-12 20:10 
AnswerRe: Drawing other stuff on? Pin
Rohit Dubey from Hyderabad22-Jan-12 20:14
Rohit Dubey from Hyderabad22-Jan-12 20:14 
QuestionImage Size Pin
downsource6-Jan-12 0:51
downsource6-Jan-12 0:51 
Questionform controls Tooltip Pin
Antonio Pelleriti14-Dec-11 21:45
Antonio Pelleriti14-Dec-11 21:45 
SuggestionCan you give use link of whole project Pin
Member 793369229-Jun-11 6:16
Member 793369229-Jun-11 6:16 
GeneralMy vote of 2 Pin
join sam lee25-Jul-10 22:51
join sam lee25-Jul-10 22:51 
GeneralMy vote of 5 Pin
Dima Popov19-Jul-10 2:53
Dima Popov19-Jul-10 2:53 
GeneralThank you! Pin
Eduard Keilholz2-Jul-10 2:41
Eduard Keilholz2-Jul-10 2:41 
AnswerFinding a working image [SOLVED] Pin
elmernite17-Dec-09 5:25
elmernite17-Dec-09 5:25 
GeneralRe: Finding a working image [SOLVED] Pin
Gee.1-Mar-10 12:13
Gee.1-Mar-10 12:13 
GeneralAnchor Controls doesnt work if using Per Pixel Alpha Blend Pin
Damon8812-Dec-09 21:03
Damon8812-Dec-09 21:03 
Generalsmall question Pin
nirishere4-Sep-09 15:46
nirishere4-Sep-09 15:46 
GeneralAdd Controls PinPopular
Gottdrak9919-Nov-08 12:23
Gottdrak9919-Nov-08 12:23 
GeneralRe: Add Controls Pin
colche25-Feb-09 19:52
colche25-Feb-09 19:52 
GeneralRe: Add Controls Pin
rbrender9-Mar-09 17:44
rbrender9-Mar-09 17:44 
GeneralRe: Add Controls Pin
Marko Padjen31-Mar-09 13:39
Marko Padjen31-Mar-09 13:39 
GeneralRe: Add Controls Pin
LatencyXXX24-Mar-12 21:36
LatencyXXX24-Mar-12 21:36 
GeneralExactly what I was looking for. Thanks. Pin
mlavenne18-Aug-08 11:36
mlavenne18-Aug-08 11:36 
QuestionGreat but can I use the function also for a control? Pin
it-bergmann14-Feb-08 1:24
it-bergmann14-Feb-08 1:24 
AnswerRe: Great but can I use the function also for a control? Pin
sebastianlaskawiec19-May-09 4:49
sebastianlaskawiec19-May-09 4:49 
Generalcool Pin
radioman.lt12-Dec-07 22:20
radioman.lt12-Dec-07 22:20 
Questionwhy doing win32 with c#? Pin
bkaratte11-Dec-07 20:46
bkaratte11-Dec-07 20:46 

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

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