Click here to Skip to main content
15,891,841 members
Articles / Programming Languages / C#

Transparency Tutorial with C# - Part 3

Rate me:
Please Sign up or sign in to vote.
4.90/5 (98 votes)
23 Mar 2004CPOL7 min read 459.8K   45.3K   340  
An article on Compositing, ColorMatrix, and ImageAttributes
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using PerPixelAlphaBlend;

namespace PerPixelAlphaBlendTest
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{

		private MyPerPixelAlphaForm TestForm;
		private Bitmap bitmap;

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		public Form1() 
		{
			InitializeComponent();
		}

		///<para>Constructs and initializes all child controls of this dialog box.</para>
		private void InitializeComponent() 
		{
			// 
			// Form1
			// 
			this.AllowDrop = true;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(112, 104);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Name = "Form1";
			this.TransparencyKey = System.Drawing.SystemColors.Control;
			this.Load += new System.EventHandler(this.Form1_Load);

		}

		
		///<para>Frees our bitmap.</para>
		protected override void Dispose(bool disposing) 
		{
			this.TestForm.Dispose();

			try 
			{
				if (disposing && bitmap != null) 
				{
					bitmap.Dispose();
					bitmap = null;
				}
			} 
			finally 
			{
				base.Dispose(disposing);
			}
		}


		private void Form1_Load(object sender, System.EventArgs e)
		{
			// TestForm will contain the per-pixel-alpha dib
			TestForm = new MyPerPixelAlphaForm();
			TestForm.Width = 192;
			TestForm.Height = 396;
			TestForm.Show();
			Bitmap btm = (Bitmap)Bitmap.FromFile("AquaMala.png");
			TestForm.SetBitmap(btm,255);
		
		}


	}
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Writer Smiley Micros
United States United States
www.smileymicros.com

Comments and Discussions