Click here to Skip to main content
11,437,978 members (52,594 online)
Click here to Skip to main content

Per Pixel Alpha Blend in C#

, 3 Jun 2004
Rate this:
Please Sign up or sign in to vote.
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 the new ways of doing the 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

31 May 2004

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

12 Feb 2002

  • Initial version.

Do you have any question or comment? Contact me!

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

Rui Lopes
Web Developer
Portugal Portugal
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pin
tornadofay5-Feb-15 17:22
professionaltornadofay5-Feb-15 17:22 
QuestionBackground FORM Pin
cThePush8-Aug-14 5:04
membercThePush8-Aug-14 5:04 
QuestionDoes this work with an MDI Child form? Pin
BardMorgan1-Jan-14 8:12
memberBardMorgan1-Jan-14 8:12 
Questioncooll gratz Pin
Member 1016021017-Jul-13 6:21
memberMember 1016021017-Jul-13 6:21 
QuestionDouble Click problem Pin
Member 815980915-Feb-13 11:52
memberMember 815980915-Feb-13 11:52 
Questionquestion Pin
Member 976512017-Jan-13 9:32
memberMember 976512017-Jan-13 9:32 
GeneralMy vote of 5 Pin
vasanth300820-Nov-12 4:39
membervasanth300820-Nov-12 4:39 
QuestionClick event Pin
mybigfatcatNL10-Aug-12 8:37
membermybigfatcatNL10-Aug-12 8:37 
GeneralMy vote of 4 Pin
Yawness13-May-12 21:51
memberYawness13-May-12 21:51 
GeneralMy vote of 5 Pin
manoj kumar choubey18-Feb-12 4:29
membermanoj kumar choubey18-Feb-12 4:29 
QuestionDrawing other stuff on? Pin
Rohit Dubey from Hyderabad22-Jan-12 21:10
memberRohit Dubey from Hyderabad22-Jan-12 21:10 
AnswerRe: Drawing other stuff on? Pin
Rohit Dubey from Hyderabad22-Jan-12 21:14
memberRohit Dubey from Hyderabad22-Jan-12 21:14 
Never mind, I created a new bitmap and just drew onto it using Graphics.FromImage.
QuestionImage Size Pin
downsource6-Jan-12 1:51
memberdownsource6-Jan-12 1:51 
Questionform controls Tooltip Pin
Antonio Pelleriti14-Dec-11 22:45
memberAntonio Pelleriti14-Dec-11 22:45 
SuggestionCan you give use link of whole project Pin
Member 793369229-Jun-11 7:16
memberMember 793369229-Jun-11 7:16 
GeneralMy vote of 2 Pin
join sam lee25-Jul-10 23:51
memberjoin sam lee25-Jul-10 23:51 
GeneralMy vote of 5 Pin
KPEBEDKO19-Jul-10 3:53
memberKPEBEDKO19-Jul-10 3:53 
GeneralThank you! Pin
Eduard Keilholz2-Jul-10 3:41
memberEduard Keilholz2-Jul-10 3:41 
AnswerFinding a working image [SOLVED] Pin
elmernite17-Dec-09 6:25
memberelmernite17-Dec-09 6:25 
GeneralRe: Finding a working image [SOLVED] Pin
Gee.1-Mar-10 13:13
memberGee.1-Mar-10 13:13 
GeneralAnchor Controls doesnt work if using Per Pixel Alpha Blend Pin
damon8812-Dec-09 22:03
memberdamon8812-Dec-09 22:03 
Generalsmall question Pin
nirishere4-Sep-09 16:46
membernirishere4-Sep-09 16:46 
GeneralAdd Controls Pin
Gottdrak9919-Nov-08 13:23
memberGottdrak9919-Nov-08 13:23 
GeneralRe: Add Controls Pin
colche25-Feb-09 20:52
membercolche25-Feb-09 20:52 
GeneralRe: Add Controls Pin
rbrender9-Mar-09 18:44
memberrbrender9-Mar-09 18:44 
GeneralRe: Add Controls Pin
Marko Padjen31-Mar-09 14:39
memberMarko Padjen31-Mar-09 14:39 
GeneralRe: Add Controls Pin
LatencyXXX24-Mar-12 22:36
memberLatencyXXX24-Mar-12 22:36 
GeneralExactly what I was looking for. Thanks. Pin
mlavenne18-Aug-08 12:36
membermlavenne18-Aug-08 12:36 
QuestionGreat but can I use the function also for a control? Pin
it-bergmann14-Feb-08 2:24
memberit-bergmann14-Feb-08 2:24 
AnswerRe: Great but can I use the function also for a control? Pin
Member 420280019-May-09 5:49
memberMember 420280019-May-09 5:49 
Generalcool Pin
radioman.lt@gmail.com12-Dec-07 23:20
memberradioman.lt@gmail.com12-Dec-07 23:20 
Questionwhy doing win32 with c#? Pin
bkaratte11-Dec-07 21:46
memberbkaratte11-Dec-07 21:46 
AnswerRe: why doing win32 with c#? Pin
tic8410-Jun-08 14:12
membertic8410-Jun-08 14:12 
GeneralVB.Net Pin
dawmail33324-Aug-07 23:47
memberdawmail33324-Aug-07 23:47 
GeneralRe: VB.Net Pin
Dj Den4ik12-Feb-08 0:05
memberDj Den4ik12-Feb-08 0:05 
GeneralRe: VB.Net Pin
Jason Newland25-Apr-12 20:31
memberJason Newland25-Apr-12 20:31 
GeneralRe: VB.Net Pin
Jason Newland25-Apr-12 20:33
memberJason Newland25-Apr-12 20:33 
GeneralGreat!!!!!!!!!!!!! Pin
shp-coding9-Aug-07 8:44
membershp-coding9-Aug-07 8:44 
GeneralWay to add some controls Pin
ihess30-Jul-07 5:17
memberihess30-Jul-07 5:17 
GeneralRe: Way to add some controls [modified] Pin
Sp3cial24-Aug-08 9:12
memberSp3cial24-Aug-08 9:12 
GeneralRe: Way to add some controls [modified] Pin
LatencyXXX24-Jan-11 0:21
memberLatencyXXX24-Jan-11 0:21 
GeneralHelp Pin
gsampath28-May-07 21:15
membergsampath28-May-07 21:15 
GeneralImage problem Pin
darb220-Apr-07 13:57
memberdarb220-Apr-07 13:57 
GeneralRe: Image problem Pin
Daryl Fish15-Jan-08 15:58
memberDaryl Fish15-Jan-08 15:58 
GeneralProblem when changing the form parent to desktop with dual-monitoring [modified] Pin
Pim-Pom7-Oct-06 2:59
memberPim-Pom7-Oct-06 2:59 
GeneralNice example, but... Pin
moebiusproject12-Sep-06 10:35
membermoebiusproject12-Sep-06 10:35 
GeneralRe: Nice example, but... Pin
Tung Nguyen15-Apr-07 18:37
memberTung Nguyen15-Apr-07 18:37 
GeneralRe: Nice example, but... Pin
tic8410-Jun-08 14:14
membertic8410-Jun-08 14:14 
GeneralProblem in design mode Pin
Capt'N Stabbin'12-Jul-06 20:09
memberCapt'N Stabbin'12-Jul-06 20:09 
GeneralRe: Problem in design mode Pin
ODaniell3-Aug-06 1:52
memberODaniell3-Aug-06 1:52 

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 | Terms of Use | Mobile
Web04 | 2.8.150506.1 | Last Updated 4 Jun 2004
Article Copyright 2002 by Rui Lopes
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid