Пример #1
0
        public static string Ratio(BulRatio value)
        {
            switch (value)
            {
            case BulRatio.RSquare:
                return("is-square");

            case BulRatio.R1by1:
                return("is-1by1");

            case BulRatio.R5by4:
                return("is-5by4");

            case BulRatio.R4by3:
                return("is-4by3");

            case BulRatio.R3by2:
                return("is-3by2");

            case BulRatio.R5by3:
                return("is-5by3");

            case BulRatio.R16by9:
                return("is-16by9");

            case BulRatio.R2by1:
                return("is-2by1");

            case BulRatio.R3by1:
                return("is-3by1");

            case BulRatio.R4by5:
                return("is-4by5");

            case BulRatio.R3by4:
                return("is-3by4");

            case BulRatio.R2by3:
                return("is-2by3");

            case BulRatio.R3by5:
                return("is-3by5");

            case BulRatio.R9by16:
                return("is-9by16");

            case BulRatio.R1by2:
                return("is-1by2");

            case BulRatio.R1by3:
                return("is-1by3");

            default:
                return("is-square");
            }
        }
Пример #2
0
        /// <summary>
        /// Find the closest supported ratio for a given width and height
        /// </summary>
        public static BulRatio FindClosest(int width, int height)
        {
            int      gcd          = GreatestCommonDivisor(width, height);
            double   ratioW       = (double)width / gcd;
            double   ratioH       = (double)height / gcd;
            double   ratio        = (double)ratioW / ratioH;
            double   closestDiff  = 99;
            BulRatio closestRatio = BulRatio.R16by9;

            foreach (var availRatio in FractionMap)
            {
                var diff = Math.Abs(availRatio.Value - ratio);
                if (diff < closestDiff)
                {
                    closestDiff  = diff;
                    closestRatio = availRatio.Key;
                }
            }

            return(closestRatio);
        }