Here you can approach the problem:
You know that the height or width of the image will be equal to the width of the frame.
Once you determine which dimension is equal to the bounding box, you use the aspect ratio of the image to calculate another dimension.
double sourceRatio = sourceImage.Width / sourceImage.Height; double targetRatio = targetRect.Width / targetRect.Height; Size finalSize; if (sourceRatio > targetRatio) { finalSize = new Size(targetRect.Width, targetRect.Width / sourceRatio); } else { finalSize = new Size(targetRect.Height * sourceRatio, targetRect.Height); }
Andrew Shepherd
source share