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
|
Graphics g;
Bitmap bmp;
public Form1()
{
InitializeComponent();
bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(bmp);
i = 0;
}
/************************ bouton menu ouvrir image ***************************/
private void ouvrirToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "fichiers bitmap (*.bmp)|*.bmp|fichiers jpg (*.jpg)|*.jpg";
Stream mystream;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((mystream = openFileDialog1.OpenFile()) != null)
{
img = new Bitmap(openFileDialog1.FileName);
pictureBox1.Image = bitmap;
g = Graphics.FromImage(bmp);
g.DrawImage(img, 0, 0);
mystream.Close();
}
}
}
/*********************** fonction pour dessiner une ligne*******************/
void dessinerLigne(Point p)
{
x = p.X;
y = p.Y;
i++;
pictureBox1.Image = bmp;
if (i % 2 != 0)
{
x2 = x;
y2 = y;
}
else
{
g.DrawLine(new Pen(Color.Red), new Point(x2, y2), new Point(x, y));
}
pictureBox1.Invalidate(pictureBox1.ClientRectangle);
}
/***************************** pour sauvegarder ******************************/
private void enregistrersousToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sauve = new SaveFileDialog();
sauve.Title = "Save as ...";
sauve.InitialDirectory = "c:/";
sauve.Filter = "Jpeg files (*.jpg)|*.jpg|Bitmap files (*.bmp)|*.bmp";
if (sauve.ShowDialog() == DialogResult.OK)
{
bmp.Save(sauve.FileName);
}
} |
Partager