5,275,589 members and growing! (17,356 online)
Email Password   helpLost your password?
Multimedia » GDI+ » General     Intermediate

Per Pixel Alpha Blend in C#

By Rui Lopes

Demonstrates how to create per pixel alpha blending windows
C#.NET 1.0, Win2K, Windows, .NET, Visual Studio, Dev

Posted: 11 Feb 2002
Updated: 3 Jun 2004
Views: 186,762
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
37 votes for this Article.
Popularity: 6.32 Rating: 4.03 out of 5
2 votes, 6.1%
1
0 votes, 0.0%
2
2 votes, 6.1%
3
3 votes, 9.1%
4
26 votes, 78.8%
5

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

About the Author

Rui Lopes



Occupation: Web Developer
Location: Portugal Portugal

Other popular GDI+ articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 77 (Total in Forum: 77) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralGreat but can I use the function also for a control?memberit-bergmann2:24 14 Feb '08  
Generalcoolmemberradioman.lt@gmail.com23:20 12 Dec '07  
Generalwhy doing win32 with c#?memberbkaratte21:46 11 Dec '07  
GeneralRe: why doing win32 with c#?membertic8414:12 10 Jun '08  
GeneralVB.Netmemberdawmail33323:47 24 Aug '07  
GeneralRe: VB.NetmemberDj Den4ik0:05 12 Feb '08  
GeneralGreat!!!!!!!!!!!!!membershp-coding8:44 9 Aug '07  
GeneralWay to add some controlsmemberihess5:17 30 Jul '07  
GeneralHelpmembergsampath21:15 28 May '07  
GeneralImage problemmemberdarb213:57 20 Apr '07  
GeneralRe: Image problemmemberDaryl Fish15:58 15 Jan '08  
GeneralProblem when changing the form parent to desktop with dual-monitoring [modified]memberPim-Pom2:59 7 Oct '06  
GeneralNice example, but...membermoebiusproject10:35 12 Sep '06  
GeneralRe: Nice example, but...memberTung Nguyen18:37 15 Apr '07  
GeneralRe: Nice example, but...membertic8414:14 10 Jun '08  
GeneralProblem in design modememberCapt'N Stabbin'20:09 12 Jul '06  
GeneralRe: Problem in design modememberODaniell1:52 3 Aug '06  
GeneralHow Can I Add Controls?memberranzige17:32 2 Dec '05  
GeneralRe: How Can I Add Controls?memberwang.songqing21:16 20 Jun '06  
Generalrecognitionmemberamir mortazavi19:36 26 Jan '05  
GeneralCan this be done in DirectX?member#teve3:58 27 Dec '04  
GeneralNice but...memberrioman6:05 6 Sep '04  
GeneralRe: Nice but...memberRui Godinho Lopes14:31 8 Sep '04  
GeneralRe: Nice but...memberrioman4:56 9 Sep '04  
GeneralRe: Nice but...sussAnonymous2:34 5 Oct '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Jun 2004
Editor: Nishant Sivakumar
Copyright 2002 by Rui Lopes
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project