0

Here is what I am trying to do. I have an Image that is 1920X1080. I am showing that image in a PictureBox and allowing a user to draw an ellipse on the screen. Once they finish that I will need to save that image off with the image and ellipse in 1 photo.

So I have tried several ways: 1. Just trying to save the image and ellipse from the PictureBox. No success doing that. 2. To store the location of the ellipse on the picture box and then redraw that ellipse on a new copy of the image using a graphics object. The problem with this one is that when it saves off the ellipse is not in the right place due to the size of the PictureBox and the original image difference.

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
   pictureBox1.Cursor = Cursors.Default;
   if (isMoving)
   {
      Circles.Add(mouseDownPosition, mouseMovePosition);
   }
   isMoving = false;
}
Bitmap newImage = new Bitmap(new Bitmap(@"C:\Personal\test\Sample.jpg"));
Graphics g = Graphics.FromImage(newImage);
foreach (var circle in Circles)
     {
        g.DrawEllipse(new Pen(Color.Red, 3), new Rectangle(circle.Key, new Size(circle.Value.X - circle.Key.X, circle.Value.Y - circle.Key.Y)));
     }
newImage.Save(@"C:\Projects\Projects\SampleCombine.jpg");

I am really just looking for a way to take exactly what I see on the PictureBox and save it as its own jpg.

My take is that I need to figure out how to reposition the "Circle" based on where it was drawn and where it should be drawn on a larger file.

Any ideas?

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
Fajhetti
  • 1
  • 1
  • 1
    In your second piece of code, you need to apply the ratio of the size of the PictureBox vs the size of the image to the size of the circles you draw on the image. That will correct your issue with the incorrect location and size of the circles – Martin May 02 '19 at 15:12
  • See [here](https://stackoverflow.com/questions/40705823/free-form-crop-selection-doesnt-work-properly/40706594#40706594) for a simple example of drawing to a zoomed picturebox. Note that all SizeModes (except) need their own calculations! - See [here](https://stackoverflow.com/questions/25086374/how-can-i-capture-as-bitmap-only-what-a-picturebox-is-displaying-without-using/25086932#25086932) for an example that save all three layers of a Picturebox.. – TaW May 02 '19 at 15:40

0 Answers0