public void Draw(KalikoImage image) { var graphics = image.Graphics; var graphicsPath = new GraphicsPath(); var stringFormat = new StringFormat { Alignment = Alignment, LineAlignment = VerticalAlignment }; graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; if (Font == null) { Font = image.Font ?? new Font("Arial", 32, FontStyle.Bold, GraphicsUnit.Pixel); } if (TargetArea == Rectangle.Empty) { TargetArea = new Rectangle(0, 0, image.Width, image.Height); } if (Point == Point.Empty) { graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, TargetArea, stringFormat); } else { graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, Point, stringFormat); } if (Rotation != 0) { var rotationTransform = new Matrix(1, 0, 0, 1, 0, 0); var bounds = graphicsPath.GetBounds(); rotationTransform.RotateAt(Rotation, new PointF(bounds.X + (bounds.Width / 2f), bounds.Y + (bounds.Height / 2f))); graphicsPath.Transform(rotationTransform); } if (TextShadow != null) { DrawShadow(graphics, graphicsPath); } if (Outline > 0) { var pen = new Pen(OutlineColor, Outline) { LineJoin = LineJoin.Round }; graphics.DrawPath(pen, graphicsPath); } if (TextBrush == null) { TextBrush = new SolidBrush(TextColor); } graphics.FillPath(TextBrush, graphicsPath); }
/// <summary>Resizes the image without any <span lang="en" id="result_box" class="short_text" xml:lang="en"><span class="hps alt-edited">consideration of the current /// ratio. If you wish to make a ratio locked resize use <see cref="Scale">Scale Method</see> instead.</span></span></summary> /// <param name="width"></param> /// <param name="height"></param> /// <seealso cref="M:CAF.Infrastructure.Core.ImageLibrary.KalikoImage.Scale(CAF.Infrastructure.Core.ImageLibrary.Scaling.ScalingBase)"></seealso> public void Resize(int width, int height) { int newWidth = width; int newHeight = height; if (newWidth == 0 && newHeight == 0) { return; } if (newWidth == 0) { newWidth = Image.Width * newHeight / Image.Height; } else if (newHeight == 0) { newHeight = Image.Height * newWidth / Image.Width; } var image = new KalikoImage(newWidth, newHeight); DrawScaledImage(image.Image, Image, 0, 0, newWidth, newHeight); Image = image.Image; }
/// <summary>Crop the image into the given dimensions.</summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="width"></param> /// <param name="height"></param> public void Crop(int x, int y, int width, int height) { var image = new KalikoImage(width, height); image.BlitImage(Image, -x, -y); Image = image.Image; }
/// <summary> /// Create a new image as a clone. /// </summary> /// <returns></returns> public KalikoImage Clone() { var newImage = new KalikoImage(Image) { Color = Color, _font = _font, BackgroundColor = BackgroundColor, TextRenderingHint = TextRenderingHint }; return(newImage); }
/// <summary>Uses the defined image as a pattern to fill the image (will be tiled if the destination image is larger than the source image)..</summary> /// <param name="image"></param> /// <example> /// <code title="Example" description="" lang="CS"> /// // Create a new image and fill the source image all over /// var image = new KalikoImage(640, 480); /// var patternImage = new KalikoImage(@"C:\Img\Checkered.png"); /// image.BlitFill(patternImage);</code> /// </example> public void BlitFill(KalikoImage image) { BlitFill(image.Image); }
/// <summary>Will take the source image and place it on the destination image at the defined coordinates.</summary> /// <param name="image"></param> /// <param name="x"></param> /// <param name="y"></param> /// <example> /// <code title="Example" description="" lang="CS"> /// // Place the source image 10 pixels from the left and 20 pixels from the top /// var sourceImage = new KalikoImage(@"C:\Img\Stamp.png"); /// image.BlitImage(sourceImage, 10, 20);</code> /// </example> public void BlitImage(KalikoImage image, int x, int y) { BlitImage(image.Image, x, y); }
/// <summary>Will take the source image and place it on the destination image at top left corner.</summary> /// <param name="image"></param> /// <example> /// <code title="Example" description="" lang="CS"> /// // Place the source image on top, left of our image /// var sourceImage = new KalikoImage(@"C:\Img\Stamp.png"); /// image.BlitImage(sourceImage);</code> /// </example> public void BlitImage(KalikoImage image) { BlitImage(image.Image, 0, 0); }
internal static void DrawScaledImage(KalikoImage destinationImage, KalikoImage sourceImage, int x, int y, int width, int height) { DrawScaledImage(destinationImage.Image, sourceImage.Image, x, y, width, height); }