private void pictureBoxPoints_MouseDown(object sender, MouseEventArgs e)
{
if (pictureBoxPoints.Image != null)
{
pointCoordinates.X = e.X;
pointCoordinates.Y = e.Y;
// Convert point coordinates from pictureBoxPoints to original frame coordinates
double xFactor = (double)pictureBoxPoints.Image.Width / pictureBoxPoints.Width;
double yFactor = (double)pictureBoxPoints.Image.Height / pictureBoxPoints.Height;
double xOffset = _convertedRectangle.X;
double yOffset = _convertedRectangle.Y;
int imageX = (int)(pointCoordinates.X * xFactor) + (int)xOffset;
int imageY = (int)(pointCoordinates.Y * yFactor) + (int)yOffset;
// Add the point to the list
_points.Add(new System.Drawing.Point(imageX, imageY));
using (Graphics g = Graphics.FromImage(bmp))
{
foreach (System.Drawing.Point point in _points)
{
g.DrawRectangle(Pens.Red, new System.Drawing.Rectangle(point.X, point.Y, 10, 10));
}
}
bmp.Save(@"d:Converted.bmp");
draw = true;
pictureBoxPoints.Invalidate();
}
}
private void pictureBoxPoints_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
if (pictureBoxPoints.Image != null && draw)
{
foreach (System.Drawing.Point point in _points)
{
e.Graphics.FillEllipse(Brushes.Red,
new Rectangle(pointCoordinates.X, pointCoordinates.Y, 10, 10));
}
draw = false;
}
}
i keep the points in the list _points
i make instance to the list once at the top of form1:
private List<System.Drawing.Point> _points = new List<System.Drawing.Point>();
but each time i click with the mouse down it’s drawing a new point but delete the last one before. and i want to keep all the points drawn on the pictureBoxPoints.