I have a C # winForm application that contains a pictureBox control. This control has a Paint event. Every time a drawing event occurs, a bitmap is dynamically created, and I perform a drawing on it. And when the user clicks the "Save" button, the edited image is saved as a jpg file.
This is normal so far. When I upload a new image in the PictureBox control, the remains of previous changes are still alive.
How to erase a bitmap and start it every time you upload a new image:
private void pb_Resim_Paint(object sender, PaintEventArgs e)
{
List<eVucutParcalari> list = new List<eVucutParcalari>(pointList.Keys);
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;
}
}
}
tugrul
source
share