Esempio n. 1
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="color">The color.</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,
     GraphicsOptions options,
     Color color,
     float thickness,
     params PointF[] points) =>
 source.DrawPolygon(options, new SolidBrush(color), thickness, points);
Esempio n. 2
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="IImageProcessingContext"/> to allow chaining of operations.</returns>
 public static IImageProcessingContext DrawPolygon(
     this IImageProcessingContext source,
     ShapeGraphicsOptions options,
     IBrush brush,
     float thickness,
     params PointF[] points) =>
 source.DrawPolygon(options, new Pen(brush, thickness), points);
Esempio n. 3
0
        private static void DrawCalibrationMarker(IImageProcessingContext context)
        {
            var currentPoint = _referencePoints[_currentPointIdx];

            context.DrawPolygon(Color.Black, 2, Square(10, currentPoint, 45))
            .DrawPolygon(Color.Black, 1, Square(1, currentPoint));
        }
Esempio n. 4
0
        private void DrawRect(IImageProcessingContext <Rgba32> image, int iwidth, int iheight, BoundingBox mainRect, BoundingBox rect, Rgba32 color)
        {
            var top    = (rect.Y - mainRect.Y) / mainRect.Height * iheight;
            var height = rect.Height / mainRect.Height * iheight;

            var left  = (rect.X - mainRect.X) / mainRect.Width * iwidth;
            var width = rect.Width / mainRect.Width * iwidth;

            var right  = left + width;
            var bottom = top + height;

            image.DrawPolygon(color, 2f, new PointF[] {
                new PointF(left, top),
                new PointF(right, top),
                new PointF(right, bottom),
                new PointF(left, bottom),
            });
        }
Esempio n. 5
0
        private void DrawCustomGauge(bool top, string labelText, string value, float ratio, int img_width, float chevronSize, float width_margin, float chart_width, float min, float max, IImageProcessingContext ctx, bool hideHeader)
        {
            float.TryParse(value, out float floatValue);
            bool missingHeaderLabel         = (labelText?.Length ?? 0) == 0;
            bool writeValueHeaderAndChevron = !hideHeader || (floatValue >= min && floatValue <= max);

            if (writeValueHeaderAndChevron && !missingHeaderLabel)
            {
                var pen = new Pen(Color.White, chevronSize + 1);

                var arrowStartX = (ratio * img_width) + width_margin;
                var arrowStartY = (HALF_WIDTH - ((chart_width / 2) * (top ? 1 : -1)));
                var arrowAddY   = arrowStartY - ((chevronSize * 2) * (top ? 1 : -1));

                var startPoint = new PointF(arrowStartX, arrowStartY);
                var right      = new PointF(arrowStartX + chevronSize, arrowAddY);
                var left       = new PointF(arrowStartX - chevronSize, arrowAddY);

                PointF[] needle = { startPoint, right, left, startPoint };

                var valueText = value.ToString();
                var textColor = (floatValue > max || floatValue < min) ? Color.Red : Color.White;
                var font      = SystemFonts.CreateFont("Arial", chevronSize * 4, FontStyle.Regular);

                var   size    = TextMeasurer.Measure(valueText, new RendererOptions(font));
                float adjustY = top ? Math.Abs(-5 - size.Height) : 5;
                arrowAddY = top ? arrowAddY - adjustY : arrowAddY + adjustY;
                var valuePoint = new PointF(HALF_WIDTH - size.Width / 2, arrowAddY);
                ctx.DrawText(valueText, font, textColor, valuePoint);

                ctx.DrawPolygon(pen, needle);
                var text = labelText != string.Empty ? labelText[0].ToString() : string.Empty;
                size          = TextMeasurer.Measure(text, new RendererOptions(SystemFonts.CreateFont("Arial", chevronSize * 3, FontStyle.Regular)));
                startPoint.Y -= top ? size.Height : 0;
                startPoint.X -= size.Width / 2;
                ctx.DrawText(text, SystemFonts.CreateFont("Arial", chevronSize * 3, FontStyle.Regular), Color.Black, startPoint);
            }
        }
Esempio n. 6
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="options">The options.</param>
 /// <param name="color">The color.</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, GraphicsOptions options, TPixel color, float thickness, params PointF[] points)
     where TPixel : struct, IPixel <TPixel>
 => source.DrawPolygon(options, new SolidBrush <TPixel>(color), thickness, points);
Esempio n. 7
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="color">The color.</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, TPixel color, float thickness, PointF[] points, GraphicsOptions options)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.DrawPolygon(new SolidBrush <TPixel>(color), thickness, points, options));
 }
Esempio n. 8
0
        public static IImageProcessingContext DrawBoxedText(this IImageProcessingContext processingContext,
                                                            Font font,
                                                            string text,
                                                            Color mainColor,
                                                            Color outlineColor,
                                                            Rectangle rectangle,
                                                            VerticalAlignment verticalAlignment,
                                                            bool debugRectangle = false)
        {
            Size  imgSize      = processingContext.GetCurrentSize();
            float targetWidth  = rectangle.Width;
            float targetHeight = rectangle.Height;

            float targetMinHeight = (int)(targetHeight * 0.95);

            var           scaledFont = font;
            FontRectangle s          = new(0, 0, float.MaxValue, float.MaxValue);

            float scaleFactor = (scaledFont.Size / 2);
            int   trapCount   = (int)scaledFont.Size * 2;

            if (trapCount < 10)
            {
                trapCount = 10;
            }

            bool isTooSmall = false;

            while ((s.Height > targetHeight || s.Height < targetMinHeight) && trapCount > 0)
            {
                if (s.Height > targetHeight)
                {
                    if (isTooSmall)
                    {
                        scaleFactor /= 2;
                    }

                    scaledFont = new Font(scaledFont, scaledFont.Size - scaleFactor);
                    isTooSmall = false;
                }

                if (s.Height < targetMinHeight)
                {
                    if (!isTooSmall)
                    {
                        scaleFactor /= 2;
                    }
                    scaledFont = new Font(scaledFont, scaledFont.Size + scaleFactor);
                    isTooSmall = true;
                }
                trapCount--;

                s = TextMeasurer.Measure(text, new RendererOptions(scaledFont)
                {
                    WrappingWidth = targetWidth
                });
            }

            var textGraphicOptions = new TextGraphicsOptions()
            {
                TextOptions =
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = verticalAlignment,
                    WrapTextWidth       = targetWidth
                }
            };
            var position = new PointF(rectangle.X, 0);

            switch (verticalAlignment)
            {
            case VerticalAlignment.Top:
                position.Y = rectangle.Y;
                break;

            case VerticalAlignment.Center:
                position.Y = rectangle.Y + rectangle.Height / 2;
                break;

            case VerticalAlignment.Bottom:
                position.Y = rectangle.Y + rectangle.Height;
                break;

            default:
                break;
            }
            if (debugRectangle)
            {
                PointF[] points = { new PointF(rectangle.X, rectangle.Y), new PointF(rectangle.X, rectangle.Y + rectangle.Height), new PointF(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height), new PointF(rectangle.X + rectangle.Width, rectangle.Y) };
                processingContext = processingContext.DrawPolygon(new Pen(Color.Red, 5), points);
            }
            return(processingContext.DrawText(textGraphicOptions, text, scaledFont, Brushes.Solid(mainColor), Pens.Solid(outlineColor, font.Size / 10), position));
        }