Click here to Skip to main content
15,890,512 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:
C#
Image img = Image.FromFile("filepath");
picBoxImageProcessing.Image = img;


zoom in:
C#
 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.
C#
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.
Posted
Updated 14-Feb-12 19:42pm
v2
Comments
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:

http://www.bobpowell.net/zoompicbox.htm

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