/// <summary>
 /// Draws the outline of the polygon with the provided brush at the provided thickness.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="color">The color.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="paths">The paths.</param>
 /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
 public static IImageProcessingContext Draw(
     this IImageProcessingContext source,
     DrawingOptions options,
     Color color,
     float thickness,
     IPathCollection paths) =>
 source.Draw(options, new SolidBrush(color), thickness, paths);
Esempio n. 2
0
 public override void DrawLine(IImageProcessingContext context, float scale, IPath path)
 {
     if (Marker == null)
     {
         base.DrawLine(context, scale, path);
     }
     else
     {
         var             simplePaths     = path.Flatten();
         PointF[]        points          = new PointF[2];
         GraphicsOptions graphicsOptions = GraphicsOptions.Default;
         foreach (var simplePath in simplePaths)
         {
             for (int i = 0; i < simplePath.Points.Count - 1; i++)
             {
                 PointF point0 = simplePath.Points[i];
                 PointF point1 = simplePath.Points[i + 1];
                 IPen   pen    = ToPen(scale, point0, point1);
                 points[0] = point0;
                 points[1] = point1;
                 context.Draw(graphicsOptions, pen, points.ToPath());
             }
         }
     }
 }
 /// <summary>
 /// Draws the outline of the polygon with the provided brush at the provided thickness.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="paths">The shapes.</param>
 /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
 public static IImageProcessingContext Draw(
     this IImageProcessingContext source,
     DrawingOptions options,
     IBrush brush,
     float thickness,
     IPathCollection paths) =>
 source.Draw(options, new Pen(brush, thickness), paths);
 /// <summary>
 /// Draws the outline of the rectangle with the provided brush at the provided thickness.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="color">The color.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="shape">The shape.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext Draw(
     this IImageProcessingContext source,
     GraphicsOptions options,
     Color color,
     float thickness,
     RectangleF shape) =>
 source.Draw(options, new SolidBrush(color), thickness, shape);
 /// <summary>
 /// Draws the provided points as an open linear path at the provided thickness with the supplied brush.
 /// </summary>
 /// <param name="source">The image processing context.</param>
 /// <param name="options">The options.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="thickness">The line thickness.</param>
 /// <param name="points">The points.</param>
 /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
 public static IImageProcessingContext DrawLines(
     this IImageProcessingContext source,
     DrawingOptions options,
     IBrush brush,
     float thickness,
     params PointF[] points) =>
 source.Draw(options, new Pen(brush, thickness), new Path(new LinearLineSegment(points)));
Esempio n. 6
0
 /// <summary>
 /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="points">The points.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext DrawPolygon(
     this IImageProcessingContext source,
     ShapeGraphicsOptions options,
     IBrush brush,
     float thickness,
     params PointF[] points) =>
 source.Draw(options, new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)));
Esempio n. 7
0
 /// <summary>
 /// Draws the outline of the polygon with the provided brush at the provided thickness.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="path">The shape.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext Draw(
     this IImageProcessingContext source,
     GraphicsOptions options,
     IBrush brush,
     float thickness,
     IPath path) =>
 source.Draw(options, new Pen(brush, thickness), path);
 /// <summary>
 /// Draws the outline of the rectangle with the provided brush at the provided thickness.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="shape">The shape.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext Draw(
     this IImageProcessingContext source,
     GraphicsOptions options,
     IBrush brush,
     float thickness,
     RectangleF shape) =>
 source.Draw(options, new Pen(brush, thickness), shape);
Esempio n. 9
0
 /// <summary>
 /// Draws the outline of the polygon with the provided brush at the provided thickness.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="color">The color.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="path">The path.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext Draw(
     this IImageProcessingContext source,
     GraphicsOptions options,
     Color color,
     float thickness,
     IPath path) =>
 source.Draw(options, new SolidBrush(color), thickness, path);
Esempio n. 10
0
 /// <summary>
 /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="points">The points.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext DrawBeziers(
     this IImageProcessingContext source,
     GraphicsOptions options,
     IBrush brush,
     float thickness,
     params PointF[] points) =>
 source.Draw(options, new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
Esempio n. 11
0
        private static IImageProcessingContext DrawBanner(this IImageProcessingContext context, WatermarkSettings settings)
        {
            var imgSize = context.GetCurrentSize();

            var options = new GraphicsOptions(true, PixelColorBlendingMode.Normal, PixelAlphaCompositionMode.SrcOver, 1);

            var points = new[] { new PointF(0, imgSize.Height), new PointF(imgSize.Width, imgSize.Height) };

            var stop = 0;

            IBrush brush = new LinearGradientBrush(
                points[0],
                points[1],
                GradientRepetitionMode.Repeat,
                settings.Colors.Select(x => new ColorStop(stop++, x)).ToArray());

            var thickness = imgSize.Height / 4.5;

            var center = imgSize.Height - thickness;

            if ((settings.Position == WatermarkPosition.Top) || (settings.Position == WatermarkPosition.TopLeft) || (settings.Position == WatermarkPosition.TopRight))
            {
                points = new[] { new PointF(0, 0), new PointF(imgSize.Width, 0) };
            }

            var fullThickness = (float)(thickness * 2);
            var pen           = new Pen(brush, fullThickness);
            var polygon       = new Polygon(new LinearLineSegment(points));

            return(context.Draw(options, pen, polygon));
        }
Esempio n. 12
0
            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);
            }
Esempio n. 13
0
        /// <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);
        }
Esempio n. 14
0
        /// <summary>
        /// Draws the outline of the polygon with the provided pen.
        /// </summary>
        /// <typeparam name="TPixel">The type of the color.</typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="options">The options.</param>
        /// <param name="pen">The pen.</param>
        /// <param name="paths">The paths.</param>
        /// <returns>The <see cref="Image{TPixel}"/>.</returns>
        public static IImageProcessingContext <TPixel> Draw <TPixel>(this IImageProcessingContext <TPixel> source, GraphicsOptions options, IPen <TPixel> pen, IPathCollection paths)
            where TPixel : struct, IPixel <TPixel>
        {
            foreach (IPath path in paths)
            {
                source.Draw(options, pen, path);
            }

            return(source);
        }
Esempio n. 15
0
        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);
            }
        }
Esempio n. 16
0
        /// <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="paths">The paths.</param>
        /// <returns>The <see cref="Image{TPixel}"/>.</returns>
        public static IImageProcessingContext Draw(
            this IImageProcessingContext source,
            ShapeGraphicsOptions options,
            IPen pen,
            IPathCollection paths)
        {
            foreach (IPath path in paths)
            {
                source.Draw(options, pen, path);
            }

            return(source);
        }
            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);
            }
 /// <summary>
 /// Draws the outline of the rectangle with the provided pen.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="pen">The pen.</param>
 /// <param name="shape">The shape.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) =>
 source.Draw(new GraphicsOptions(), pen, shape);
 /// <summary>
 /// Draws the outline of the rectangle 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="shape">The shape.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext Draw(
     this IImageProcessingContext source,
     GraphicsOptions options,
     IPen pen,
     RectangleF shape) =>
 source.Draw(options, pen, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
Esempio n. 20
0
 /// <summary>
 /// Draws the outline of the polygon with the provided pen.
 /// </summary>
 /// <param name="source">The image this method extends.</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, IPen pen, IPath path) =>
 source.Draw(GraphicsOptions.Default, pen, path);
Esempio n. 21
0
 /// <summary>
 /// Draws the provided Points as a closed Linear Polygon with the provided Pen.
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="pen">The pen.</param>
 /// <param name="points">The points.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> DrawPolygon <TPixel>(this IImageProcessingContext <TPixel> source, GraphicsOptions options, IPen <TPixel> pen, params PointF[] points)
     where TPixel : struct, IPixel <TPixel>
 => source.Draw(options, pen, new Polygon(new LinearLineSegment(points)));
Esempio n. 22
0
 /// <summary>
 /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
 /// </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="thickness">The thickness.</param>
 /// <param name="points">The points.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> DrawPolygon <TPixel>(this IImageProcessingContext <TPixel> source, IBrush <TPixel> brush, float thickness, params PointF[] points)
     where TPixel : struct, IPixel <TPixel>
 => source.Draw(new Pen <TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)));
Esempio n. 23
0
 /// <summary>
 /// Draws the outline of the polygon with the provided brush at the provided thickness.
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="color">The color.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="shape">The shape.</param>
 /// <param name="options">The options.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> Draw <TPixel>(this IImageProcessingContext <TPixel> source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.Draw(new SolidBrush <TPixel>(color), thickness, shape, options));
 }
Esempio n. 24
0
 /// <summary>
 /// Draws the outline of the polygon with the provided brush at the provided thickness.
 /// </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="thickness">The thickness.</param>
 /// <param name="shape">The shape.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> Draw <TPixel>(this IImageProcessingContext <TPixel> source, IBrush <TPixel> brush, float thickness, RectangleF shape)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.Draw(new Pen <TPixel>(brush, thickness), shape));
 }
Esempio n. 25
0
 /// <summary>
 /// Draws the outline of the polygon with the provided pen.
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="pen">The pen.</param>
 /// <param name="shape">The shape.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> Draw <TPixel>(this IImageProcessingContext <TPixel> source, IPen <TPixel> pen, RectangleF shape)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.Draw(pen, shape, GraphicsOptions.Default));
 }
Esempio n. 26
0
            public override void Draw(Visualizer v, PointF center, IImageProcessingContext context)
            {
                var path = Path.Translate(center);

                context.Draw(v.shapeGraphicsOptions, v.foregroundBrush, v.edgeThickness, new PathCollection(path));
            }
 /// <summary>
 /// Draws the outline of the polygon with the provided pen.
 /// </summary>
 /// <param name="source">The image this method extends.</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, IPen pen, IPath path) =>
 source.Draw(new ShapeGraphicsOptions(), pen, path);
Esempio n. 28
0
 /// <summary>
 /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
 /// </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="thickness">The thickness.</param>
 /// <param name="points">The points.</param>
 /// <param name="options">The options.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> DrawPolygon <TPixel>(this IImageProcessingContext <TPixel> source, IBrush <TPixel> brush, float thickness, PointF[] points, GraphicsOptions options)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.Draw(new Pen <TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)), options));
 }
Esempio n. 29
0
 /// <summary>
 /// Draws the provided Points as a closed Linear Polygon with the provided Pen.
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="pen">The pen.</param>
 /// <param name="points">The points.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> DrawPolygon <TPixel>(this IImageProcessingContext <TPixel> source, IPen <TPixel> pen, PointF[] points)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default));
 }
Esempio n. 30
0
 /// <summary>
 /// Draws the outline of the polygon with the provided pen.
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="pen">The pen.</param>
 /// <param name="shape">The shape.</param>
 /// <param name="options">The options.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> Draw <TPixel>(this IImageProcessingContext <TPixel> source, IPen <TPixel> pen, RectangleF shape, GraphicsOptions options)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.Draw(pen, new SixLabors.Shapes.RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height), options));
 }