bonjour !
voila j'ai un problème avec le pictureBox ??? j'ai fait un code qui charge une image dans pictureBox.
en suite j'ai fait des graphiques (lignes, points) que je dois afficher aussi dans la même pictureBox !!!!
voici mon code complet :
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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            g = Graphics.FromImage(bmp);
 
        }
 
        private Bitmap bmp;
        private Graphics g;
        int x, y, x2, y2, i;
 
 
 
 
        private void openShapeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = "Choose a shape...";
            openFileDialog1.DefaultExt = "jpg";
            openFileDialog1.Filter = "Files image JPEG (*.jpg)|*.jpg|Files bitmap(*.bmp)|*.bmp";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Bitmap img = new Bitmap(openFileDialog1.FileName);
                pictureBox1.Image = img;
 
            }
 
        }
 
            // cette methode c'est juste pour recuperer la prostion de la souris quand je clique dans pictureBox
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            x = e.Location.X;     
            y = e.Location.Y;
            i++;
 
            dessin();
        }
        private void dessin()
        {
 
            g.DrawEllipse(new Pen(Color.Red, 2.0f), new Rectangle(new Point(x, y), new Size(4, 4)));
  // les testes c'est juste pour faire quand je clique deux fois je dessine une ligne
            if (i % 2 != 0)
            {
                x2 = x;
                y2 = y;
            }
            else
            {
                g.DrawLine(new Pen(Color.Red), new Point(x2, y2), new Point(x, y));
                pictureBox1.Image = bmp;
            }
        }
    }
}
le problème ici c'est que quand je charge l'image sur la pictureBox en suite je dessine mon graphique la le graphique écrase l'image ??? qu'est ce que je dois faire pour éviter ce problème ? j'ai pense a un truc et ça marche ! c'est de mettre l'image en arrière plan de la pictureBox mais je pense pas que c'est une bonne idée !! car je veux récupérer a la fin l'image avec les graphiques (lignes et points) dessus voila !!!
merci
a+