Click here to Skip to main content
15,746,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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;

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.
Updated 14-Feb-12 19:42pm
BillWoodruff 17-Feb-12 2:47am    
Please confirm this a WinForms question, and that you are using WinForms Panel, and PictureBox controls.

Show us the code you use now to "select a specific region drawing a rectangle on the zoomed image and then crop" on the image at default (?) resolution: before you resize the image and set 'SizeMode to 'StretchImage.

Is there a particular reason you are using 'BackGroundImage 'Tile mode on the PictureBox ?

This (very old) article might give you an idea for a new approach:

1 solution

from my point of view...

A WPF Custom Control for Zooming and Panning[^]

please refer the above link.

solution to you problem from my view would be like >>

select the rectangle to crop. then save the cropped image

then resize the iamage as per your requirement(zoom percent).

in croping and resizing i guess i can help.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900