ImageGlass.ImageBox.ZoomToFit C# (CSharp) Method

ZoomToFit() public method

Zooms to the maximum size for displaying the entire image within the bounds of the control.
public ZoomToFit ( ) : void
return void
        public virtual void ZoomToFit()
        {
            if (!ViewSize.IsEmpty)
            {
                Rectangle innerRectangle;
                double zoom;
                double aspectRatio;

                innerRectangle = GetInsideViewPort(true);

                if (ViewSize.Width > ViewSize.Height)
                {
                    aspectRatio = (double)innerRectangle.Width / ViewSize.Width;
                    zoom = aspectRatio * 100.0;

                    if (innerRectangle.Height < ((ViewSize.Height * zoom) / 100.0))
                    {
                        aspectRatio = (double)innerRectangle.Height / ViewSize.Height;
                        zoom = aspectRatio * 100.0;
                    }
                }
                else
                {
                    aspectRatio = (double)innerRectangle.Height / ViewSize.Height;
                    zoom = aspectRatio * 100.0;

                    if (innerRectangle.Width < ((ViewSize.Width * zoom) / 100.0))
                    {
                        aspectRatio = (double)innerRectangle.Width / ViewSize.Width;
                        zoom = aspectRatio * 100.0;
                    }
                }

                Zoom = (int)Math.Round(Math.Floor(zoom));
            }
        }
ImageBox