Example #1
0
        public BitmapTransformationChain Transform(Bitmap original, Size size)
        {
            var chain = new BitmapTransformationChain(original, logException);

            chain.TransformCopying(_ => resize(_, size));
            chain.TransformInplace(removeCorners);

            return(chain);
        }
Example #2
0
        public BitmapTransformationChain TransformArt(Bitmap original, Size size)
        {
            var chain = new BitmapTransformationChain(original, logException);

            if (!original.Size.FitsIn(size))
            {
                chain.TransformCopying(_ => resize(_, size));
            }

            return(chain);
        }
Example #3
0
        public BitmapTransformationChain TransformForgeImage(Bitmap original, Size size)
        {
            var frameDetector = new BmpFrameDetector(original, SizeCropped);

            frameDetector.Execute();
            var frame = frameDetector.Frame;

            var chain = new BitmapTransformationChain(original, logException);

            chain.TransformCopying(_ => resize(_, size, frame));
            return(chain);
        }
Example #4
0
        public static Bitmap HalfResizeDpi(this Bitmap original, bool preventMoire = false)
        {
            var originalSize = original.Size;
            var reducedSize  = originalSize.HalfByDpi();

            if (originalSize == reducedSize)
            {
                return(original);
            }

            int stepsCount;

            if (preventMoire)
            {
                var   originalToReducedRatio = originalSize.DivideBy(reducedSize);
                float maxRatio = originalToReducedRatio.Max();
                stepsCount = (int)Math.Round((maxRatio - 1) * 3f);
            }
            else
            {
                stepsCount = 1;
            }

            SizeF delta = originalSize.Minus(reducedSize).DivideBy(
                reducedSize.MultiplyBy(stepsCount));

            using (var chain = new BitmapTransformationChain(original, reThrow))
            {
                for (int k = stepsCount - 1; k >= 0; k--)
                {
                    Size currentSize = reducedSize.MultiplyBy(delta.MultiplyBy(k).Plus(1f)).Round();
                    chain.TransformCopying(bmp => bmp.FitIn(currentSize));
                }

                return(chain.Result);
            }
        }