private void DrawPadButton(IImageProcessingContext context, PointF point, Image icon, string label, bool pressed, bool enabled) { // Use relative positions so we can center the the entire drawing later. float iconX = 0; float iconY = 0; float iconWidth = icon.Width; float iconHeight = icon.Height; var labelRectangle = MeasureString(label, _labelsTextFont); float labelPositionX = iconWidth + 8 - labelRectangle.X; float labelPositionY = 3; float fullWidth = labelPositionX + labelRectangle.Width + labelRectangle.X; float fullHeight = iconHeight; // Convert all relative positions into absolute. float originX = (int)(point.X - fullWidth / 2); float originY = (int)(point.Y - fullHeight / 2); iconX += originX; iconY += originY; var iconPosition = new Point((int)iconX, (int)iconY); var labelPosition = new PointF(labelPositionX + originX, labelPositionY + originY); var selectedRectangle = new RectangleF(originX - 2 * _padPressedPenWidth, originY - 2 * _padPressedPenWidth, fullWidth + 4 * _padPressedPenWidth, fullHeight + 4 * _padPressedPenWidth); var boundRectangle = new RectangleF(originX, originY, fullWidth, fullHeight); boundRectangle.Inflate(4 * _padPressedPenWidth, 4 * _padPressedPenWidth); context.Fill(_panelBrush, boundRectangle); context.DrawImage(icon, iconPosition, 1); context.DrawText(label, _labelsTextFont, _textNormalColor, labelPosition); if (enabled) { if (pressed) { context.Draw(_padPressedPen, selectedRectangle); } } else { // Just draw a semi-transparent rectangle on top to fade the component with the background. // TODO (caian): This will not work if one decides to add make background semi-transparent as well. context.Fill(_disabledBrush, boundRectangle); } }
static IImageProcessingContext DrawTextOldVersion( IImageProcessingContext source, DrawingOptions options, TextOptions textOptions, string text, IBrush brush, IPen pen) { IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, textOptions); var pathOptions = new DrawingOptions() { GraphicsOptions = options.GraphicsOptions }; if (brush != null) { source.Fill(pathOptions, brush, glyphs); } if (pen != null) { source.Draw(pathOptions, pen, glyphs); } return(source); }
/// <summary> /// Draws the text using the default resolution of <value>72dpi</value> onto the the image filled via the brush then outlined via the pen. /// </summary> /// <typeparam name="TPixel">The type of the color.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="text">The text.</param> /// <param name="font">The font.</param> /// <param name="brush">The brush.</param> /// <param name="pen">The pen.</param> /// <param name="location">The location.</param> /// <param name="options">The options.</param> /// <returns> /// The <see cref="Image{TPixel}" />. /// </returns> public static IImageProcessingContext <TPixel> DrawText <TPixel>(this IImageProcessingContext <TPixel> source, string text, Font font, IBrush <TPixel> brush, IPen <TPixel> pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel <TPixel> { float dpiX = DefaultTextDpi; float dpiY = DefaultTextDpi; var style = new RendererOptions(font, dpiX, dpiY, location) { ApplyKerning = options.ApplyKerning, TabWidth = options.TabWidth, WrappingWidth = options.WrapTextWidth, HorizontalAlignment = options.HorizontalAlignment, VerticalAlignment = options.VerticalAlignment }; IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, style); var pathOptions = (GraphicsOptions)options; if (brush != null) { source.Fill(brush, glyphs, pathOptions); } if (pen != null) { source.Draw(pen, glyphs, pathOptions); } return(source); }
private void drawText(IImageProcessingContext pc, string message, string foreColor, string backColor) { var fColor = Color.ParseHex(foreColor); var bColor = Color.ParseHex(backColor); pc.Fill(bColor); pc.DrawText(message, _font, fColor, new PointF(0, 0)); }
/// <summary> /// Flood fills the image in the shape of the provided polygon with the specified brush. /// </summary> /// <typeparam name="TPixel">The type of the color.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="brush">The brush.</param> /// <param name="path">The shape.</param> /// <param name="options">The graphics options.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext <TPixel> Fill <TPixel>(this IImageProcessingContext <TPixel> source, IBrush <TPixel> brush, Action <PathBuilder> path, GraphicsOptions options) where TPixel : struct, IPixel <TPixel> { var pb = new PathBuilder(); path(pb); return(source.Fill(brush, pb.Build(), options)); }
/// <summary> /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// </summary> /// <typeparam name="TPixel">The type of the color.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="brush">The brush.</param> /// <param name="paths">The shapes.</param> /// <param name="options">The graphics options.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext <TPixel> Fill <TPixel>(this IImageProcessingContext <TPixel> source, IBrush <TPixel> brush, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel <TPixel> { foreach (IPath s in paths) { source.Fill(brush, s, options); } return(source); }
public static void Round(this IImageProcessingContext <Rgba32> img, float radius) { var size = img.GetCurrentSize(); var gOptions = new GraphicsOptions(true) { AlphaCompositionMode = PixelAlphaCompositionMode.DestOut }; img.Fill(gOptions, Rgba32.Black, BuildCorners(size.Width, size.Height, radius)); }
public override void Render(IImageProcessingContext <Rgba32> context, Rectangle cellArea, RenderCell cell) { Rgba32?renderingColor = GetRenderingColor(cell); if (renderingColor == null) { return; } context.Fill(renderingColor.Value, cellArea); }
/// <summary> /// Flood fills the image within the provided region defined by an <see cref="PathBuilder"/> method /// using the specified brush. /// </summary> /// <param name="source">The image processing context.</param> /// <param name="options">The graphics options.</param> /// <param name="brush">The brush.</param> /// <param name="region">The <see cref="PathBuilder"/> method defining the region to fill.</param> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> public static IImageProcessingContext Fill( this IImageProcessingContext source, DrawingOptions options, IBrush brush, Action <PathBuilder> region) { var pb = new PathBuilder(); region(pb); return(source.Fill(options, brush, pb.Build())); }
/// <summary> /// Flood fills the image in the shape of the provided polygon with the specified brush. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="options">The graphics options.</param> /// <param name="brush">The brush.</param> /// <param name="path">The shape.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext Fill( this IImageProcessingContext source, ShapeGraphicsOptions options, IBrush brush, Action <PathBuilder> path) { var pb = new PathBuilder(); path(pb); return(source.Fill(options, brush, pb.Build())); }
private static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius) { var(width, height) = ctx.GetCurrentSize(); var corners = BuildCorners(width, height, cornerRadius); var graphicOptions = new GraphicsOptions(enableAntialiasing: true) { AlphaCompositionMode = PixelAlphaCompositionMode.DestOut }; return(ctx.Fill(graphicOptions, Rgba32.Red, corners)); }
private static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius) { var size = ctx.GetCurrentSize(); var corners = BuildCorners(size.Width, size.Height, cornerRadius); var graphicOptions = new GraphicsOptions(true) { AlphaCompositionMode = PixelAlphaCompositionMode.DestOut // enforces that any part of this shape that has color is punched out of the background }; return(ctx.Fill(graphicOptions, Rgba32.LimeGreen, corners)); }
public override void DrawPoint(IImageProcessingContext context, float scale, PointF point) { if (scale == 0) { return; } if (Size.Width == 0 || Size.Height == 0) { return; } float width = scale * Size.Width; float height = scale * Size.Height; RectangleF rectangle = new RectangleF(point.X - width / 2, point.Y - height / 2, scale * Size.Width, scale * Size.Height); PointF[] points = null; switch (PointShape) { case PointShape.Diamond: points = rectangle.ToRegularPoints(4); break; case PointShape.Ellipse: points = rectangle.ToEllipsePoints(); break; case PointShape.Hexagon: points = rectangle.ToRegularPoints(6); break; case PointShape.Pentagon: points = rectangle.ToRegularPoints(5); break; case PointShape.Rectangle: points = rectangle.ToPoints(); break; case PointShape.Star: points = rectangle.ToStarsPoints(); break; case PointShape.Triangle: points = rectangle.ToRegularPoints(3); break; } IPath path = points.ToPath(); path = path.Rotate(Angle); path = path.Translate(Offset); context.Fill(Color, path); DrawOutLine(context, scale, path); }
/// <summary> /// Flood fills the image in the shape of the provided polygon with the specified brush. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="options">The graphics options.</param> /// <param name="brush">The brush.</param> /// <param name="paths">The shapes.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext Fill( this IImageProcessingContext source, ShapeGraphicsOptions options, IBrush brush, IPathCollection paths) { foreach (IPath s in paths) { source.Fill(options, brush, s); } return(source); }
public static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius) { Size size = ctx.GetCurrentSize(); IPathCollection corners = BuildCorners(size.Width, size.Height, cornerRadius); ctx.SetGraphicsOptions(new GraphicsOptions() { Antialias = true, AlphaCompositionMode = PixelAlphaCompositionMode.DestOut }); return(ctx.Fill(Color.Red, corners)); }
// This method can be seen as an inline implementation of an `IImageProcessor`: // (The combination of `IImageOperations.Apply()` + this could be replaced with an `IImageProcessor`) private static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius) { Size size = ctx.GetCurrentSize(); IPathCollection corners = BuildCorners(size.Width, size.Height, cornerRadius); var graphicOptions = new GraphicsOptions(true) { AlphaCompositionMode = PixelAlphaCompositionMode.DestOut // enforces that any part of this shape that has color is punched out of the background }; // mutating in here as we already have a cloned original // use any color (not Transparent), so the corners will be clipped return(ctx.Fill(graphicOptions, Rgba32.LimeGreen, corners)); }
public static void ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius) { var(width, height) = ctx.GetCurrentSize(); var corners = BuildCorners(width, height, cornerRadius); var graphicOptions = new GraphicsOptions(true) { AlphaCompositionMode = PixelAlphaCompositionMode.DestOut // Enforces that any part of this shape that has color is punched out of the background }; // Mutating in here as we already have a cloned original // use any color (not Transparent), so the corners will be clipped ctx.Fill(graphicOptions, Rgba32.LimeGreen, corners); }
public static IImageProcessingContext ApplyRoundedCorners( this IImageProcessingContext ctx) { (int width, int height) = ctx.GetCurrentSize(); IPathCollection corners = BuildCorners(width, height); var graphicOptions = new GraphicsOptions(true) { // enforces that any part of this shape that has color is punched out of the background AlphaCompositionMode = PixelAlphaCompositionMode.DestOut }; // use any color (not Transparent), so the corners will be clipped return(ctx.Fill(graphicOptions, Rgba32.LimeGreen, corners)); }
public void DrawPolygon(IImageProcessingContext context, float scale, IPath path) { if (context == null || path == null) { return; } IBrush brush = GetBrush(); if (brush == null) { return; } context.Fill(brush, path); DrawOutLine(context, scale, path); }
private static IImageProcessingContext DrawUsername(this IImageProcessingContext source, Font userFont, Font discFont, string username, string discrim, PointF location) { var options = new TextGraphicsOptions { TextOptions = { ApplyKerning = true, VerticalAlignment = VerticalAlignment.Bottom } }; var userOptions = new RendererOptions(userFont, location) { ApplyKerning = options.TextOptions.ApplyKerning, VerticalAlignment = options.TextOptions.VerticalAlignment }; IPathCollection userGlyphs = TextBuilder.GenerateGlyphs(username, userOptions); while (userGlyphs.Bounds.Width > MaxUsernameLength) { var trimmedUser = new StringBuilder(); trimmedUser.Append(username.Remove(username.Length - 1)); username = trimmedUser.ToString(); trimmedUser.Append("..."); userGlyphs = TextBuilder.GenerateGlyphs(trimmedUser.ToString(), userOptions); } var discrimLocation = new PointF(userGlyphs.Bounds.Right + 2, location.Y); var discrimOptions = new RendererOptions(discFont, discrimLocation) { ApplyKerning = options.TextOptions.ApplyKerning, VerticalAlignment = options.TextOptions.VerticalAlignment }; IPathCollection discrimGlyphs = TextBuilder.GenerateGlyphs(discrim, discrimOptions); source.Fill(Brushes.Solid(Color.DarkSlateGray), userGlyphs); source.Fill(Brushes.Solid(Color.DarkSlateGray), discrimGlyphs); return(source); }
// https://github.com/SixLabors/Samples/blob/master/ImageSharp/AvatarWithRoundedCorner/Program.cs public static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius) { Size size = ctx.GetCurrentSize(); IPathCollection corners = BuildCorners(size.Width, size.Height, cornerRadius); ctx.SetGraphicsOptions(new GraphicsOptions() { Antialias = true, AlphaCompositionMode = PixelAlphaCompositionMode.DestOut // enforces that any part of this shape that has color is punched out of the background }); foreach (var c in corners) { ctx = ctx.Fill(SixLabors.ImageSharp.Color.Red, c); } return(ctx); }
// This method can be seen as an inline implementation of an `IImageProcessor`: // (The combination of `IImageOperations.Apply()` + this could be replaced with an `IImageProcessor`) private static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius) { Size size = ctx.GetCurrentSize(); IPathCollection corners = BuildCorners(size.Width, size.Height, cornerRadius); ctx.SetGraphicsOptions(new GraphicsOptions() { Antialias = true, AlphaCompositionMode = PixelAlphaCompositionMode.DestOut // enforces that any part of this shape that has color is punched out of the background }); // mutating in here as we already have a cloned original // use any color (not Transparent), so the corners will be clipped foreach (var c in corners) { ctx = ctx.Fill(Color.Red, c); } return(ctx); }
static IImageProcessingContext DrawTextOldVersion( IImageProcessingContext source, TextGraphicsOptions options, string text, Fonts.Font font, IBrush brush, IPen pen, PointF location) { var style = new Fonts.RendererOptions(font, options.TextOptions.DpiX, options.TextOptions.DpiY, location) { ApplyKerning = options.TextOptions.ApplyKerning, TabWidth = options.TextOptions.TabWidth, WrappingWidth = options.TextOptions.WrapTextWidth, HorizontalAlignment = options.TextOptions.HorizontalAlignment, VerticalAlignment = options.TextOptions.VerticalAlignment }; IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, style); var pathOptions = new ShapeGraphicsOptions() { GraphicsOptions = options.GraphicsOptions }; if (brush != null) { source.Fill(pathOptions, brush, glyphs); } if (pen != null) { source.Draw(pathOptions, pen, glyphs); } return(source); }
public void Render(GraphBuilder context, IImageProcessingContext <Rgba32> renderContext, GraphicsOptions options) { float leftBoundPixel = context.GridRegion.Left; float rightBoundPixel = context.GridRegion.Right; float topBoundPixel = context.GridRegion.Top; float bottomBoundPixel = context.GridRegion.Bottom; var data = Data.Select(point => new { PixelLocation = context.ToPixels(((PointF)point)) + context.GridRegion.Position() + context.Origin, Data = point }).Where(point => point.PixelLocation.X > leftBoundPixel && point.PixelLocation.X <rightBoundPixel && point.PixelLocation.Y> topBoundPixel && point.PixelLocation.Y < bottomBoundPixel) .OrderBy(point => point.Data.X) .ToArray(); while (data.Length > 0) { List <PointF> pixels = data.TakeWhile(p => !p.Data.BreakLine).Select(p => p.PixelLocation).ToList(); if (pixels.Count < data.Length) { // add the line-breaking point pixels.Add(data[pixels.Count].PixelLocation); } if (LinePen != null) { renderContext.DrawLines(LinePen, pixels.ToArray(), options); } if (DataPointCircleRadius > 0) { foreach (var pixel in pixels) { renderContext.Fill(PointColor, new SixLabors.Shapes.EllipsePolygon(pixel, DataPointCircleRadius), options); } } data = data.Skip(pixels.Count).ToArray(); } }
/// <summary> /// Draws the outline of the polygon with the provided pen. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="options">The options.</param> /// <param name="pen">The pen.</param> /// <param name="path">The path.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext Draw( this IImageProcessingContext source, GraphicsOptions options, IPen pen, IPath path) => source.Fill(options, pen.StrokeFill, new ShapePath(path, pen));
/// <summary> /// Flood fills the image in the shape of a Linear polygon described by the points /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="color">The color.</param> /// <param name="points">The points.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext FillPolygon( this IImageProcessingContext source, Color color, params PointF[] points) => source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)));
/// <summary> /// Flood fills the image in the shape of a Linear polygon described by the points /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="brush">The brush.</param> /// <param name="points">The points.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext FillPolygon( this IImageProcessingContext source, IBrush brush, params PointF[] points) => source.Fill(brush, new Polygon(new LinearLineSegment(points)));
/// <summary> /// Flood fills the image in the shape of the provided polygon with the specified brush. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="color">The color.</param> /// <param name="paths">The paths.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext Fill( this IImageProcessingContext source, Color color, IPathCollection paths) => source.Fill(new SolidBrush(color), paths);
/// <summary> /// Flood fills the image in the shape of the provided polygon with the specified brush. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="options">The options.</param> /// <param name="color">The color.</param> /// <param name="paths">The paths.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext Fill( this IImageProcessingContext source, ShapeGraphicsOptions options, Color color, IPathCollection paths) => source.Fill(options, new SolidBrush(color), paths);
/// <summary> /// Flood fills the image in the shape of the provided polygon with the specified brush. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="brush">The brush.</param> /// <param name="paths">The paths.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext Fill( this IImageProcessingContext source, IBrush brush, IPathCollection paths) => source.Fill(source.GetShapeGraphicsOptions(), brush, paths);