public ImagePreset(string name, ScalingBase scaleMethod)
 {
     Name             = name;
     ScaleMethod      = scaleMethod;
     PreventUpscaling = true;
     Quality          = 90;
     Filters          = new List <IFilter>();
     Version          = 1;
 }
Пример #2
0
        public ResizeCommand(ScalingType scalingType, int size)
        {
            _size = size;
            switch (scalingType)
            {
            case ScalingType.CropScaling:
                _scaling = new CropScaling(_size, _size);
                break;

            case ScalingType.FitScaling:
                _scaling = new FitScaling(_size, _size);
                break;

            case ScalingType.PadScaling:
                _scaling = new PadScaling(_size, _size);
                break;
            }
        }
Пример #3
0
        /// <summary>
        /// 缩略图的截图模式是:当原图宽高比按照缩略图时缩放
        /// </summary>
        /// <param name="originalImagePath"></param>
        /// <param name="thumbnailPath"></param>
        /// <param name="extName"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="scale">Crop:取中间部分;Fit:按比例缩放,自动调整尺寸;Pad:按比例缩放,保持尺寸,不足部分填白</param>
        /// <param name="position">水印位置</param>
        /// <param name="waterMarkingPath">水印图片路劲</param>
        public void MakeThumbnail(string originalImagePath, string thumbnailPath, string extName, int width, int height, ThumbnailMethod scale = ThumbnailMethod.Fit, WaterMarkingPosition?position = null, string waterMarkingPath = "")
        {
            if (!File.Exists(originalImagePath))
            {
                return;
            }
            var image = new KalikoImage(originalImagePath)
            {
                BackgroundColor = Color.White
            };
            var         format      = GetImageFormat(extName);
            ScalingBase scalingBase = null;

            switch (scale)
            {
            case ThumbnailMethod.Crop:
                scalingBase = new CropScaling(width, height);
                break;

            case ThumbnailMethod.Fit:
                scalingBase = new FitScaling(width, height);
                break;

            case ThumbnailMethod.Pad:
                scalingBase = new PadScaling(width, height);
                break;

            default:
                scalingBase = new CropScaling(width, height);
                break;
            }
            var imageThumb = image.Scale(scalingBase);

            AddWaterMarking(position, waterMarkingPath, imageThumb);
            imageThumb.SaveImage(thumbnailPath, format);
            image.Dispose();
            imageThumb.Dispose();
        }
Пример #4
0
 /// <summary>Scale the image using a defined scaling engine which can be <see cref="Scaling.CropScaling">CropScaling Class</see> will crop the image so that the final result always
 /// has the given dimension, <see cref="Scaling.FitScaling">FitScaling Class</see> will ensure that the complete image is visible inside the given
 /// dimension or <see cref="Scaling.PadScaling">PadScaling Class</see> that will pad the image so that it cover the given dimension.</summary>
 /// <param name="scaleEngine"></param>
 /// <returns></returns>
 /// <seealso cref="Scaling.CropScaling"></seealso>
 /// <seealso cref="Scaling.FitScaling"></seealso>
 /// <seealso cref="Scaling.PadScaling"></seealso>
 public KalikoImage Scale(ScalingBase scaleEngine) {
     var resizedImage = scaleEngine.Scale(this);
     return resizedImage;
 }
Пример #5
0
        /// <summary>Scale the image using a defined scaling engine which can be <see cref="Scaling.CropScaling">CropScaling Class</see> will crop the image so that the final result always
        /// has the given dimension, <see cref="Scaling.FitScaling">FitScaling Class</see> will ensure that the complete image is visible inside the given
        /// dimension or <see cref="Scaling.PadScaling">PadScaling Class</see> that will pad the image so that it cover the given dimension.</summary>
        /// <param name="scaleEngine"></param>
        /// <returns></returns>
        /// <seealso cref="Scaling.CropScaling"></seealso>
        /// <seealso cref="Scaling.FitScaling"></seealso>
        /// <seealso cref="Scaling.PadScaling"></seealso>
        public KalikoImage Scale(ScalingBase scaleEngine)
        {
            var resizedImage = scaleEngine.Scale(this);

            return(resizedImage);
        }
Пример #6
0
        /// <summary>Scale the image using a defined scaling engine which can be <see cref="Scaling.CropScaling">CropScaling Class</see> will crop the image so that the final result always
        /// has the given dimension, <see cref="Scaling.FitScaling">FitScaling Class</see> will ensure that the complete image is visible inside the given
        /// dimension or <see cref="Scaling.PadScaling">PadScaling Class</see> that will pad the image so that it cover the given dimension.</summary>
        /// <param name="scaleEngine">Scale engine to use</param>
        /// <param name="preventUpscaling">Prevent upscaling</param>
        /// <returns></returns>
        /// <seealso cref="Scaling.CropScaling"></seealso>
        /// <seealso cref="Scaling.FitScaling"></seealso>
        /// <seealso cref="Scaling.PadScaling"></seealso>
        public KalikoImage Scale(ScalingBase scaleEngine, bool preventUpscaling)
        {
            var resizedImage = scaleEngine.Scale(this, preventUpscaling);

            return(resizedImage);
        }