Bonjour, cette question étant souvent abordée, je vous la repose néanmoins avec mon code afin que l'on puisse m'expliquer et/ou corriger ce qui ne va pas.
Est-il correct d'utiliser System.Drawing.Bitmap("test.bmp") pour obtenir une image (que j'ai appelée par exemple test.bmp) contenue dans ma picturebox ou mon problème vient-il de là? Faut-il plutôt un png?
Merci d'avance à tous!
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);
}