0

Using C# I write a Windows Forms program to crop a picture of an object, but the position of the object is different within the picture. How can I fix it? Here is the code and result.

screenshot

I think that problem is in the mouse up function. Can you guys check for me?

private void viewBox_MouseUp(object sender, MouseEventArgs e)
{
    Point p = new Point(0, 0);
    if (isMouseDown == true)
    {
        endPosition = e.Location;               
        isMouseDown = false;

        if (rect != null && rect.Width != 0 && rect.Height != 0)
        {
            Bitmap bit = new Bitmap(viewBox.Image, viewBox.Width, viewBox.Height);
            Bitmap cropImg = new Bitmap(rect.Width, rect.Height);
            Graphics g = Graphics.FromImage(cropImg);
            g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel);
            ObjectViewBox.Image = cropImg;
        }                                
    }
}
dymanoid
  • 14,771
  • 4
  • 36
  • 64
HueNguyen
  • 1
  • 2

0 Answers0