Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 C# picture tranparency
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

IT-3pjg3
Starting Member

1 Posts

Posted - 15 March 2005 :  02:48:55  Show Profile
I’m trying to make a character walking on a coloured path. But my character is a square image and I don’t want to see all of the image but some of this image must be transparent so you can see the background of the path. This must be an smart device application and a picurebox.

Does someone have a solution?

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 22 March 2005 :  15:00:19  Show Profile
You need to cycle through the image pixel by pixel (in red) and set it's opacity, i've done it on here to "watermark" the footer.

You need the quantizer classes from MSDN to optimize the image, here's my code from the above site

public void Scale(int width, int height)
		{
			OctreeQuantizer quantizer = new OctreeQuantizer(255, 8);

			Bitmap thumb = new Bitmap(width, height);
			Graphics g = Graphics.FromImage(thumb);
			g.InterpolationMode = InterpolationMode.HighQualityBicubic;
			g.DrawImage(image, new Rectangle(0,0,thumb.Width,thumb.Height),0,0,image.Width,image.Height,GraphicsUnit.Pixel);
			image.Dispose();

			if (_text.Length > 0)
			{
				Font font = new Font("Verdana", 8, FontStyle.Bold);
				Bitmap watermark = new Bitmap(thumb.Width, 20);

				Graphics g2 = Graphics.FromImage(watermark);
				g2.FillRectangle(
					new SolidBrush(Color.Black),
					new RectangleF(0, 0, watermark.Width, watermark.Height));
				g2.DrawString(_text, font, new SolidBrush(Color.White), 1, 3);
				g2.Dispose();

				Color color;

				for (int py = 0; py < watermark.Height; py++)
				{
					for (int px = 0; px < watermark.Width; px++)
					{
						color = watermark.GetPixel(px, py);
						watermark.SetPixel(px, py, Color.FromArgb(96, color.R, color.G, color.B));
					}
				} 

				g.DrawImage(watermark, 0, thumb.Height - 20);
			}

			g.DrawRectangle(new Pen(Color.Black), 0, 0, thumb.Width - 1, thumb.Height - 1);
			g.Dispose();

			Bitmap quantized = quantizer.Quantize(thumb);
			thumb.Dispose();

			HttpContext.Current.Response.ContentType = "image/gif";
			quantized.Save(HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
			quantized.Dispose();
		}

The UK MkIVs Forum

Edited by - DavidRhodes on 22 March 2005 15:02:33
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000 Version 3.4.07