Avatar of Stealthrt
Stealthrt
Flag for United States of America

asked on 

Checking image width/height and determine what image box to place it in

Hey all I have the following image box' sizes on my WPF form:
 Box |Width |Height
 ----|------|------
 1   |357   |272
 ----|------|------
 2   |357   |272
 ----|------|------
 3   |365   |460
 ----|------|------
 4   |365   |265
 ----|------|------
 5   |715   |455
 ----|------|------
 6   |360   |465
 ----|------|------
 7   |360   |465
 ----|------|------
 8   |360   |465
 ----|------|------
 9   |540   |290
 ----|------|------
 10  |540   |290

Open in new window

So visually it would look something like this:
 --------------------------
 |       |        |       |
 |   1   |    2   |       |
 |----------------|   3   |
 |                |       |
 |                |-------|
 |       5        |       |
 |                |   4   |
 |------------------------|
 |        |       |       |
 |   6    |   7   |   8   |
 |        |       |       |
 |------------------------|
 |            |           |
 |     9      |     10    |
 --------------------------

Open in new window

So what my goal is is to get the current image I am wanting to place into a box and get its width and height and from that determine the best box to place it in so that it will show the image:

- Without black borders on either the left/right or top/bottom (or both).
- Not chop off the important areas of the image (mostly the middle section moving out).

I have decided to use Magick.NET in order to ease the pain of doing something like this from scratch. So when I determine what box I will be placing the image into then I can use the Magick.NET to crop it using:

Resize with something like this:
imgStream.Crop(width, height, Gravity.Center);

Open in new window

or
MagickGeometry size = new MagickGeometry(width, height);
size.IgnoreAspectRatio = maintainAspectRatio;
// Adjust geometry offset to center of image (same as `-gravity Center`)
size.Y = imgStream.Height / 2 - height / 2;
size.X = imgStream.Width / 2 - width / 2;
imgStream.Crop(size);

Open in new window

So to sum up the above - I am in need of finding the best box to place the image into before I go and use Magick.NET on it.
Images and PhotosC#Math / ScienceMicrosoft Visual Studio

Avatar of undefined
Last Comment
d-glitch

8/22/2022 - Mon