Ejemplo n.º 1
0
        public void SameSourceAndDestSizeResultInMultiplicatorOf6()
        {
            var sourceSize = new Size(463, 600);
            var destSize = new Size(180, 180);

            var multi = new Cropping().GetMultiplicator(sourceSize, destSize);
            Assert.Equal(0.39, multi, 2);
        }
        private WebImage CropImage(WebImage image, int width, int height)
        {
            var cropper = new Cropping();
            double multi = cropper.GetMultiplicator(new Size(image.Width, image.Height), new Size(width, height));

            double fWidth = image.Width*multi;
            double fHeight = image.Height*multi;

            image = image.Resize((int)fWidth, (int)fHeight,preserveAspectRatio:false    );
            int iWidth = image.Width;
            int iHeight = image.Height;
            int top = Math.Max((iHeight - height) / 2, 0);
            int left = Math.Max((iWidth - width) / 2, 0);
            int bottom = Math.Max(iHeight - (height + top), 0);
            int right = Math.Max(iWidth - (width + left), 0);
            return image.Crop(top, left, bottom, right);
        }