1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| private void pictureBox1_OnPaint(object sender, EventArgs e)
{
// Create a red and black bitmap to demonstrate transparency.
System.Drawing.Image bmp = new System.Drawing.Bitmap("test.bmp");
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
// Detect image attributes
System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
// for a color from the bitmap
attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0));
// for a color from the system color
// attr.SetColorKey(System.Drawing.Color.DeepPink, System.Drawing.Color.DeepPink);
// Draw the image using the image attributes.
System.Drawing.Rectangle rDest = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);
g.DrawImage(bmp, rDest, 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attr);
} |
Partager