CKFinder.Connector.ImageTools.GetAspectRatioSize C# (CSharp) Method

GetAspectRatioSize() private static method

private static GetAspectRatioSize ( int maxWidth, int maxHeight, int actualWidth, int actualHeight ) : Size
maxWidth int
maxHeight int
actualWidth int
actualHeight int
return System.Drawing.Size
        private static Size GetAspectRatioSize( int maxWidth, int maxHeight, int actualWidth, int actualHeight )
        {
            // Creates the Size object to be returned
            Size oSize = new System.Drawing.Size( maxWidth, maxHeight );

            // Calculates the X and Y resize factors
            float iFactorX = (float)maxWidth / (float)actualWidth;
            float iFactorY = (float)maxHeight / (float)actualHeight;

            // If some dimension have to be scaled
            if ( iFactorX != 1 || iFactorY != 1 )
            {
                // Uses the lower Factor to scale the opposite size
                if ( iFactorX < iFactorY ) { oSize.Height = (int)Math.Round( (float)actualHeight * iFactorX ); }
                else if ( iFactorX > iFactorY ) { oSize.Width = (int)Math.Round( (float)actualWidth * iFactorY ); }
            }

            if ( oSize.Height <= 0 ) oSize.Height = 1;
            if ( oSize.Width <= 0 ) oSize.Width = 1;

            // Returns the Size
            return oSize;
        }