Enregistrement d'un bitmap.
Bonjour,
J'ai un formulaire qui me permet de dessiner sur une pictureBox à l'aide d'un graphic. Cela fonctionne bien. Mon problème est que je n'arrive pas à le relier à un bitmap, car lorsque j'enregistre mon bitmap, l'image enregistrer est juste un fond noir.
Code:
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
| public partial class Form1 : Form
{
Point lastPoint = new Point();
private List<Point> points = new List<Point>();
private Graphics graphic;
Pen pen = new Pen(Color.Black);
Bitmap btmp;
public Form1()
{
InitializeComponent();
btmp = new Bitmap(pictureBox2.Width, pictureBox2.Height);
graphic = Graphics.FromImage(btmp);
}
private void onMouseMouve(object sender, MouseEventArgs e)
{
points.Add(new Point(e.X, e.Y));
graphic = pictureBox2.CreateGraphics();
graphic.DrawLine(pen, lastPoint.X, lastPoint.Y, e.X, e.Y);
lastPoint.X = e.X;
lastPoint.Y = e.Y;
Invalidate();
}
private void onMouseDown(object sender, MouseEventArgs e)
{
lastPoint.X = e.X;
lastPoint.Y = e.Y;
points.Clear();
points.Add(lastPoint);
}
private void button1_Click(object sender, System.EventArgs e)
{
pictureBox2.Image = btmp;
btmp.Save("signature.png", ImageFormat.Png);
} |
Si quelqu'un sait d'où ça vient je suis preneur :mrgreen:.
Merci pour votre attention.