Hi I have C# winForm application which holds a pictureBox control. This control has a Paint event.Every time paint event is fired , a Bitmap is dynamically created and I perform some drawing on it.
And when user clicks "save" button , edited image is saved as jpg file. It's OK until now.
But when I load a new image in pictureBox control remains of previous edits are still alive.
How can I erase the bitmap and start fresh each time I load a new image.
Here is the code snippet for PaintEvet
private void pb_Resim_Paint(object sender, PaintEventArgs e)
{
List<eVucutParcalari> list = new List<eVucutParcalari>(pointList.Keys);
// Loop through list
foreach (eVucutParcalari k in list)
{
Dictionary<Point, Color> dicItem = pointList[k];
foreach (KeyValuePair<Point, Color> pair in dicItem)
{
Point p = pair.Key;
Color c = pair.Value;
SolidBrush brush = new SolidBrush(c);
if (pb_Resim.Image == null)
return;
Bitmap bmp = new Bitmap(pb_Resim.Image);
Graphics gr = Graphics.FromImage(bmp);
gr.FillRectangle(brush, p.X, p.Y, 5, 5);
pb_Resim.Image = bmp;
}
}
}
Thanks in advance