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 l'image contenue dans ma picturebox ou mon problème vient-il de là?

Merci d'avance à tous!


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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);
        }