/// <summary>
        ///Generates a Thumbnail
        /// </summary>
        /// <param name="image"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        protected virtual Image GenerateThumbnail(Image image, ThumbnailOption option)
        {
            var height = option.Height ?? image.Height;
            var width  = option.Width ?? image.Width;
            var color  = ColorTranslator.FromHtml(option.BackgroundColor);

            Image thumbnail = null;

            switch (option.ResizeMethod)
            {
            case ResizeMethod.FixedSize:
                thumbnail = _imageResizer.FixedSize(image, width, height, color);
                break;

            case ResizeMethod.FixedWidth:
                thumbnail = _imageResizer.FixedWidth(image, width, color);
                break;

            case ResizeMethod.FixedHeight:
                thumbnail = _imageResizer.FixedHeight(image, height, color);
                break;

            case ResizeMethod.Crop:
                thumbnail = _imageResizer.Crop(image, width, height, option.AnchorPosition);
                break;
            }
            return(thumbnail);
        }
Beispiel #2
0
        /// <summary>
        ///Generates a Thumbnail
        /// </summary>
        /// <param name="image"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        protected virtual Image <Rgba32> GenerateThumbnail(Image <Rgba32> image, ThumbnailOption option)
        {
            var height = option.Height ?? image.Height;
            var width  = option.Width ?? image.Width;

            var color = Rgba32.Transparent;

            if (!string.IsNullOrWhiteSpace(option.BackgroundColor))
            {
                color = Rgba32.FromHex(option.BackgroundColor);
            }

            Image <Rgba32> result;

            switch (option.ResizeMethod)
            {
            case ResizeMethod.FixedSize:
                result = _imageResizer.FixedSize(image, width, height, color);
                break;

            case ResizeMethod.FixedWidth:
                result = _imageResizer.FixedWidth(image, width, color);
                break;

            case ResizeMethod.FixedHeight:
                result = _imageResizer.FixedHeight(image, height, color);
                break;

            case ResizeMethod.Crop:
                result = _imageResizer.Crop(image, width, height, option.AnchorPosition);
                break;

            default:
                throw new ArgumentOutOfRangeException($"ResizeMethod {option.ResizeMethod.ToString()} not supported.");
            }

            return(result);
        }