In my app (winforms), I'd like to load in different images. These images have different sizes, and different aspect ratios (let's say I have a 400x400, and a 1920x1200.) Now I have a picturebox to put these images in, and the picturebox's SizeMode property is set to Zoom.
Now I have an image in a picturebox, that is resized to fit within the picuterbox's boundaries. But if the picturebox has a different aspect ratio than the image has, I will be left with some unwanted empty space. Setting the SizeMode to stretch, is not an option.
?: So I'd like to know, if there is a way to get the size of the auto-resized image, so I can change the size of the picturebox accordingly.
Image myImg = new Image.FromFile(..//landscape.jpg)
int getWidth = myImg.Width;
int getHeight = myImg.Height;
// This does not work, as it gets the original size of the image (eg: in case of a 1920x1200, it gets 1920 and 1200 respectively)
This is what happens right now:
This is what I'd like to have:
Because the app should be able to process any image, I need to set these values dynamically, so no values can be preset.