using System; using System.Linq; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing.Imaging; using System.Drawing; namespace ProjetoSamu.TranspUtil { public class TransparentImage : Control { private Bitmap imagem; protected override void OnPaintBackground(PaintEventArgs e) { } public void setImage(Bitmap img){ imagem = img; this.Invalidate(); } public Bitmap getImage() { return this.imagem; } private bool bPaintOnce = false; protected override void OnPaint(PaintEventArgs e) { if (!bPaintOnce) { bPaintOnce = true; this.Visible = false; this.Parent.Invalidate(this.Bounds); this.Parent.Update(); this.Visible = true; return; } else { bPaintOnce = false; Graphics g = e.Graphics; //g.DrawImage(imagem, 0, 0); ImageAttributes iattrb = new ImageAttributes(); Color transColor = imagem.GetPixel(0, 0); iattrb.SetColorKey(transColor, transColor); g.DrawImage(imagem, new Rectangle(0, 0, imagem.Width, imagem.Height), 0, 0, imagem.Width, imagem.Height, GraphicsUnit.Pixel, iattrb); g.Dispose(); } } } }