I have a picture box in a windows forms project, the picture box has the size property set to Stretch. I figured that clicking on a point on the picture box would mirror a click on the same exact co-ordinate on the image nested inside that picture box, but when I click on a point on the picture box, the calculation does not accurately mirror that point on the image. I capture the point clicked using the picture box's MouseClick event handler, then I perform calculations on point to draw over on the image and then I draw a circle over that point on the original image. The point drawn on the image is a little to the left and top of the actual position I clicked on the picture box. I need to get the point right so my user can click on any section of the image and add a watermark. Here is my code
private void PictureBox1_MouseClick(object sender, MouseEventArgs e){
//calculate the point on the image
var imageX = e.X *(pictureBox1.Image.Width/pictureBox1.Width);
var imageY = e.Y * (pictureBox1.Image.Height/pictureBox1.Height);
var point = new Point(imageX, imageY);
//draw a circle on that point
var circle = new CircleF(point, 5);
var path = paths[index];
var image = new Image<Bgr, byte>(path);
image.Draw(circle, new Bgr(Color.Red),5);
pictureBox1.Image = ToBitmap(image);
}
The circle is draw some distance to the left and some distance to the top of the actual position I clicked on the picture box. How can I fix this?