ImageGlass.ImageBox.ZoomAuto C# (CSharp) Method

ZoomAuto() public method

[PHAP] Zooms to the maximum size for displaying the entire image within the bounds of the control. If image size is smaller than viewer size, keep its original size.
public ZoomAuto ( ) : void
return void
        public virtual void ZoomAuto()
        {
            if (!ViewSize.IsEmpty)
            {
                Rectangle innerRectangle;
                double zoom;
                double aspectRatio;

                innerRectangle = GetInsideViewPort(true);
                
                if (ViewSize.Width <= innerRectangle.Width && ViewSize.Height <= innerRectangle.Height)
                {
                    zoom = 100.0;
                }
                else
                {
                    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