Example #1
0
        public Image PrepareImage(Func <Image, Size, Bitmap> resizing, Image image, ImageSize size)
        {
            if (resizing is null)
            {
                throw new NullReferenceException($"Parameter `{nameof(resizing)}` cannot be null!");
            }

            if (image is null)
            {
                throw new NullReferenceException($"Parameter `{nameof(image)}` cannot be null!");
            }

            if (((IProportionFormatter)this).CanBeFormatted(image, size) == false)
            {
                throw new NotSupportedImageSizeException(image, size);
            }

            var rate = size.GetImageSizeRate();

            if (rate is null)
            {
                rate = Math.Min(image.Width, image.Height);
            }

            return(resizing(image, new Size(rate.Value, rate.Value)));
        }
Example #2
0
        public Image PrepareImage(Func <Image, Size, Bitmap> resizing, Image image, ImageSize size)
        {
            if (resizing is null)
            {
                throw new NullReferenceException($"Parameter `{nameof(resizing)}` cannot be null!");
            }

            if (image is null)
            {
                throw new NullReferenceException($"Parameter `{nameof(image)}` cannot be null!");
            }

            if (((IProportionFormatter)this).CanBeFormatted(image, size) == false)
            {
                throw new NotSupportedImageSizeException(image, size);
            }

            var rate = size.GetImageSizeRate();

            var imageSize = rate is null
                ? new Size(image.Width, image.Height)
                : image.Width > image.Height
                    ? new Size(rate.Value, (int)((decimal)image.Height / image.Width * rate.Value))
                    : new Size((int)((decimal)image.Width / image.Height * rate.Value), rate.Value);

            return(resizing(image, imageSize));
        }