Click here to Skip to main content
15,867,594 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 599.3K   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

 
GeneralMy vote of 5 Pin
EAHMK28-Jun-20 5:07
professionalEAHMK28-Jun-20 5:07 
QuestionHow I can just place a transparent image to a certain position? Pin
NotNiceCream20-Dec-16 12:41
NotNiceCream20-Dec-16 12:41 
AnswerRe: How I can just place a transparent image to a certain position? Pin
NotNiceCream20-Dec-16 16:15
NotNiceCream20-Dec-16 16:15 
GeneralMy vote of 5 Pin
tornadofay5-Feb-15 16:22
professionaltornadofay5-Feb-15 16:22 
QuestionBackground FORM Pin
cThePush8-Aug-14 4:04
cThePush8-Aug-14 4:04 
QuestionDoes this work with an MDI Child form? Pin
BardMorgan1-Jan-14 7:12
BardMorgan1-Jan-14 7:12 
Questioncooll gratz Pin
Member 1016021017-Jul-13 5:21
Member 1016021017-Jul-13 5:21 
QuestionDouble Click problem Pin
Member 815980915-Feb-13 10:52
Member 815980915-Feb-13 10:52 
Questionquestion Pin
wootowl17-Jan-13 8:32
wootowl17-Jan-13 8:32 
GeneralMy vote of 5 Pin
vasanth300820-Nov-12 3:39
vasanth300820-Nov-12 3:39 
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 

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.