Пример #1
0
        //public static IBitmap Recolor(this IBitmap bitmap, Color srcColor, Color newColor, bool keepAlpha = true)
        //{
        //	var source = bitmap?.SKBitmap;
        //	if (source == null || newColor == srcColor)
        //		return bitmap;

        //	if (keepAlpha) {
        //		return bitmap.Recolor((color) => {
        //			if (color.R == srcColor.R && color.G == srcColor.G && color.B == srcColor.B) {
        //				return new Color(newColor.R, newColor.G, newColor.B, color.A);
        //			} else {
        //				return color;
        //			}
        //		});
        //	} else {
        //		return bitmap.Recolor((color) => (color == srcColor) ? newColor : color);
        //	}
        //}

        public static IBitmap Resize(this IBitmap bitmap, Size newSize)
        {
            int newWidth  = (int)Math.Round(newSize.Width);
            int newHeight = (int)Math.Round(newSize.Height);

            return(bitmap.Resize(newWidth, newHeight));
        }
Пример #2
0
        public static IBitmap <T> ProcessTemplate <T>(Template <T> template, IBitmap <T> clearLogo)
        {
            IBitmap <T> output;

            IBitmap <T> resizedLogo = clearLogo.Clone().TrimPixels().Rotate(template.LogoRotation);

            double perfectRatio    = (double)(template.LogoArea.Width) / (double)(template.LogoArea.Height);
            double ratioDifference = ((double)(resizedLogo.Width) / (double)(resizedLogo.Height)) - perfectRatio;


            if (Math.Abs(ratioDifference) < template.AspectRange)
            {
                resizedLogo = resizedLogo.Resize(template.LogoArea.Size, template.Enlarge);
            }
            else
            {
                resizedLogo = resizedLogo.ResizeToFit(template.LogoArea.Size, template.Enlarge);
            }

            int logoX = 0;
            int logoY = 0;

            switch (template.LogoHorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                logoX = template.LogoArea.X;
                break;

            case HorizontalAlignment.Middle:
                logoX = template.LogoArea.X + ((template.LogoArea.Width / 2) - (resizedLogo.Width / 2));
                break;

            case HorizontalAlignment.Right:
                logoX = template.LogoArea.X + template.LogoArea.Width - resizedLogo.Width / 2;
                break;
            }

            switch (template.LogoVerticalAlignment)
            {
            case VerticalAlignment.Top:
                logoY = template.LogoArea.Y;
                break;

            case VerticalAlignment.Middle:
                logoY = template.LogoArea.Y + ((template.LogoArea.Height / 2) - (resizedLogo.Height / 2));
                break;

            case VerticalAlignment.Bottom:
                logoY = template.LogoArea.Y + template.LogoArea.Height - resizedLogo.Height;
                break;
            }

            output = template.Image.Clone().DrawImage(resizedLogo.Bitmap, new Point(logoX, logoY));


            return(output);
        }
Пример #3
0
 /// <summary>
 /// Resizes the image to the specified width and height
 /// </summary>
 /// <remarks>
 /// This will scale the existing image to the desired size
 /// </remarks>
 /// <param name="width">New width for the resized image</param>
 /// <param name="height">New height for the resized image</param>
 public void Resize(int width, int height)
 {
     handler.Resize(width, height);
 }