Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image Scaling of picture box

i got a problem with image scaling in C#.

I have a picture Box with given Size : e.g. width = 800px height = 600px

I am loading different images into that picture box, small ones ( 400x400) and big ones (800+ x 600+)

My images are getting resized if they do not fit into box. But they are always resized to MAX width and height of PictureBox. So the aspect ratio is destroyed.

Can anybody help to identify / fix the problem?

Classes:

Form1.cs

ImageHandling.cs (commented out)

ImageUtilities.cs

Examples:

Problem 1: My Version
enter image description here

vs Original Source enter image description here

Problem 2:
My Version
enter image description here

vs Original Source
enter image description here

How i want it:

Solution
enter image description here

like image 593
pila Avatar asked Sep 28 '12 19:09

pila


People also ask

How do I resize an image in box?

If you use the Windows Forms PictureBox control on a form, you can set the SizeMode property on it to: Align the picture's upper left corner with the control's upper left corner. Center the picture within the control. Adjust the size of the control to fit the picture it displays.

What is scale of an image?

In computer graphics and digital imaging, image scaling refers to the resizing of a digital image. In video technology, the magnification of digital material is known as upscaling or resolution enhancement.

What is the default value of the PictureBox controls SizeMode property?

The default is Normal.


1 Answers

this.PictureBox1.SizeMode = PictureBoxSizeMode.Zoom; 

Set that property to your PictureBox and the size of the image will increased or decreased to fit the PictureBox maintaining the size ratio.

For more info: http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode.aspx

like image 78
Forte L. Avatar answered Oct 05 '22 02:10

Forte L.