Esempio n. 1
0
        private double GetProportionsFactor(ImageCroppingProportions proportions, double defaultValue)
        {
            switch (proportions)
            {
            case ImageCroppingProportions.Original:
                return(m_imageSize.Width / m_imageSize.Height);

            case ImageCroppingProportions.Widescreen:
                return(16.0 / 9.0);

            case ImageCroppingProportions.Square:
                return(1.0);

            case ImageCroppingProportions.ThreeOverTwo:
                return(3.0 / 2.0);

            case ImageCroppingProportions.FourOverThree:
                return(4.0 / 3.0);

            case ImageCroppingProportions.FourOverSix:
                return(4.0 / 6.0);

            case ImageCroppingProportions.FiveOverSeven:
                return(5.0 / 7.0);

            case ImageCroppingProportions.EightOverTen:
                return(8.0 / 10.0);

            default:
                return(defaultValue);
            }
        }
        public static string Convert(ImageCroppingProportions proportions)
        {
            switch (proportions)
            {
            case ImageCroppingProportions.Custom:
                return("Custom");

            case ImageCroppingProportions.Original:
                return(Strings.Android.CropOriginal);

            case ImageCroppingProportions.Square:
                return(Strings.Android.CropSquare);

            // Portrait
            case ImageCroppingProportions.TwoOverThree:
                return("2:3");

            case ImageCroppingProportions.ThreeOverFive:
                return("3:5");

            case ImageCroppingProportions.ThreeOverFour:
                return("3:4");

            case ImageCroppingProportions.FourOverFive:
                return("4:5");

            case ImageCroppingProportions.FiveOverSeven:
                return("5:7");

            case ImageCroppingProportions.NineOverSixteen:
                return("9:16");

            // Landscape
            case ImageCroppingProportions.ThreeOverTwo:
                return("3:2");

            case ImageCroppingProportions.FiveOverThree:
                return("5:3");

            case ImageCroppingProportions.FourOverThree:
                return("4:3");

            case ImageCroppingProportions.FiveOverFour:
                return("5:4");

            case ImageCroppingProportions.SevenOverFive:
                return("7:5");

            case ImageCroppingProportions.SixteenOverNine:
                return("16:9");

            default:
                return(proportions.ToString());
            }
        }
Esempio n. 3
0
        private double GetProportionsFactor(ImageCroppingProportions proportions, double defaultValue)
        {
            switch (proportions)
            {
            case ImageCroppingProportions.Original:
                return(m_imageSize.Width / m_imageSize.Height);

            case ImageCroppingProportions.Square:
                return(1.0);

            // Portrait
            case ImageCroppingProportions.TwoOverThree:
                return(2.0 / 3.0);

            case ImageCroppingProportions.ThreeOverFive:
                return(3.0 / 5.0);

            case ImageCroppingProportions.ThreeOverFour:
                return(3.0 / 4.0);

            case ImageCroppingProportions.FourOverFive:
                return(4.0 / 5.0);

            case ImageCroppingProportions.FiveOverSeven:
                return(5.0 / 7.0);

            case ImageCroppingProportions.NineOverSixteen:
                return(9.0 / 16.0);

            // Landscape
            case ImageCroppingProportions.ThreeOverTwo:
                return(3.0 / 2.0);

            case ImageCroppingProportions.FiveOverThree:
                return(5.0 / 3.0);

            case ImageCroppingProportions.FourOverThree:
                return(4.0 / 3.0);

            case ImageCroppingProportions.FiveOverFour:
                return(5.0 / 4.0);

            case ImageCroppingProportions.SevenOverFive:
                return(7.0 / 5.0);

            case ImageCroppingProportions.SixteenOverNine:
                return(16.0 / 9.0);

            default:
                return(defaultValue);
            }
        }
Esempio n. 4
0
        private void OnProportionsChanged(ImageCroppingProportions oldValue, ImageCroppingProportions newValue)
        {
            var cropScale             = m_cropRectangle.Width / m_cropRectangle.Height;
            var proportionalCropScale = GetProportionsFactor(Proportions, cropScale);

            if (cropScale < proportionalCropScale)
            {
                var cropHeight = m_cropRectangle.Width / proportionalCropScale;

                m_cropRectangle.Y      = Clamp(m_cropRectangle.Y + (m_cropRectangle.Height - cropHeight) / 2.0, 0.0, m_imageSize.Height - cropHeight);
                m_cropRectangle.Height = cropHeight;
            }
            else
            {
                var cropWidth = m_cropRectangle.Height * proportionalCropScale;

                m_cropRectangle.X     = Clamp(m_cropRectangle.X + (m_cropRectangle.Width - cropWidth) / 2.0, 0.0, m_imageSize.Width - cropWidth);
                m_cropRectangle.Width = cropWidth;
            }

            UpdateCropRectangle(m_cropRectangle, true);
        }