All pastes #590281 Raw Edit

Mine

public text v1 · immutable
#590281 ·published 2007-06-26 13:52 UTC
rendered paste body
		private void Alpha (int n, float a)
		{
			ColorMatrix cm = new ColorMatrix (new float[][] {
				new float[] 	{1,	0,	0, 	0, 	0}, //R
				new float[] 	{0,	1,	0, 	0, 	0}, //G
				new float[] 	{0,	0,	1, 	0, 	0}, //B
				new float[] 	{0,	0,	0, 	a, 	0}, //A
				new float[] 	{0,	0,	0, 	0, 	1}, //Translation
			  });

			using (Bitmap bmp = new Bitmap (1, 4)) {
//				bmp.SetPixel (0, 0, Color.White);
				bmp.SetPixel (0, 0, Color.FromArgb (255, 255, 155, 155));hol
				bmp.SetPixel (0, 1, Color.Red);
				bmp.SetPixel (0, 2, Color.Lime);
				bmp.SetPixel (0, 3, Color.Blue);
				using (Bitmap b = new Bitmap (1, 4)) {
					using (Graphics g = Graphics.FromImage (b)) {
						ImageAttributes ia = new ImageAttributes ();
						ia.SetColorMatrix (cm);
						g.DrawImage (bmp, new Rectangle (0, 0, 1, 4), 0, 0, 1, 4, GraphicsUnit.Pixel, ia);
//						Assert.AreEqual (Color.FromArgb (n, 255, 255, 255), b.GetPixel (0,0), "0,0");
Console.WriteLine ("{0}\t{2}\t{1}", n, b.GetPixel (0, 0), a);
//						Assert.AreEqual (Color.FromArgb (n, 255, 0, 0), b.GetPixel (0,1), "0,1");
//						Assert.AreEqual (Color.FromArgb (n, 0, 255, 0), b.GetPixel (0,2), "0,2");
//						Assert.AreEqual (Color.FromArgb (n, 0, 0, 255), b.GetPixel (0,3), "0,3");
					}
				}
			}
		}

		[Test]
		public void XAlpha ()
		{
			// 0 == 0,0,0,0
			for (int i = 1; i < 256; i++) {
				Alpha (i, (float) i / 255);
			}
		}