1
Answer

How to crop an image that is zoomed(zoomed in/out)

Photo of learner learner

learner learner

13y
3.6k
1
How to crop an image that is zoomed(zoomed in/out). Cropping works fine when the image is normal, that is not zoomed. I have used a panel whose AutoScroll property is true and a picturebox inside the panel whose sizemode property is AutoSize and BackgroundImageLayout is Tile.

Load image:
Image img = Image.FromFile("filepath");
picBoxImageProcessing.Image = img;

zoom in:

zoomFactor += 1;
picBoxImageProcessing.Size = new Size((img.Width * zoomFactor), (img.Height * zoomFactor));
picBoxImageProcessing.SizeMode = PictureBoxSizeMode.StretchImage;

cropping:
Draw a rectangular shape on the image and then crop.
Crop(Image img, Rectangle r)
{
//
}

In this way when i zoom in first and then select a specific region drawing a rectangle on the zoomed image and then crop then another region is cropped rather than i have selected.
I have got many application for image processing but I couldn't solve my problem.

thanks in advance.

Answers (1)

0
Photo of Frogleg
NA 7.9k 33k 13y

Attachment cropping.zip

You will have to calculate your cropbox info (size and location) that you have drawn in your picturebox relative to the zoomed image top left corner - not the picturebox top left
As the original bitmap is the original size, you will have to shrink the crop box according to a ratio you will have had to determine
I included a sketch to show what i mean