Ejemplo n.º 1
0
        private static void Transform(Image <Rgba32> image, int width, int height, FitMethod method)
        {
            ResizeMode?resizeMode = null;

            switch (method)
            {
            case FitMethod.Contain:
                resizeMode = ResizeMode.Max;
                break;

            case FitMethod.Cover:
                resizeMode = ResizeMode.Crop;
                break;

            case FitMethod.Fill:
                resizeMode = ResizeMode.Stretch;
                break;

            case FitMethod.ScaleDown:
                if (image.Width > width || image.Height > height)
                {
                    resizeMode = ResizeMode.Max;
                }
                break;
            }

            if (resizeMode.HasValue)
            {
                image.Mutate(x => x.Resize(new ResizeOptions()
                {
                    Size     = new Size(width, height),
                    Mode     = resizeMode.Value,
                    Position = AnchorPositionMode.Center
                }));
            }
        }
Ejemplo n.º 2
0
 private static void Generate(Image <Rgba32> image, string destination, int width, int height, FitMethod method, IEncoder encoder)
 {
     Validate(width, height);
     Transform(image, width, height, method);
     Save(image, destination, encoder);
 }
Ejemplo n.º 3
0
 private static void Generate(string source, string destination, int width, int height, FitMethod method, IEncoder encoder)
 {
     using (Image <Rgba32> image = SixLabors.ImageSharp.Image.Load(source))
     {
         Generate(image, destination, width, height, method, encoder);
     }
 }