示例#1
0
 /// <summary>
 /// Draws the text onto the image filled via the brush.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="options">The options.</param>
 /// <param name="text">The text.</param>
 /// <param name="font">The font.</param>
 /// <param name="color">The color.</param>
 /// <param name="location">The location.</param>
 /// <returns>
 /// The <see cref="Image{TPixel}" />.
 /// </returns>
 public static IImageProcessingContext DrawText(
     this IImageProcessingContext source,
     TextGraphicsOptions options,
     string text,
     Font font,
     Color color,
     PointF location) =>
 source.DrawText(options, text, font, Brushes.Solid(color), null, location);
示例#2
0
        public void DrawPatternPolygon3Core()
        {
            using (var image = new Image <Rgba32>(800, 800))
            {
                image.Mutate(x => x.Fill(CoreBrushes.BackwardDiagonal(Color.HotPink)));

                using (var stream = new MemoryStream())
                {
                    image.SaveAsBmp(stream);
                }
            }
        }
        public void Draw()
        {
            if (ImageWrapper != null)
            {
                // Get size of the image
                var width  = (int)ImageWrapper.ActualWidth;
                var height = (int)ImageWrapper.ActualHeight;

                using (image = new Image <Rgba32>(width, height))
                {
                    // Draw triangle
                    image.Mutate((ctx) =>
                    {
                        offset = new PointF(width / 2, height / 2);

                        // Define pens and inks
                        var pinkPen       = Pens.Solid(Rgba32.ParseHex("#FFC0CB"), 1);
                        var greenPen      = Pens.Solid(Rgba32.ParseHex("#228B22"), 1);
                        var blackPen      = Pens.Solid(Rgba32.ParseHex("#000000"), 1);
                        var blackTransPen = Pens.Solid(Rgba32.ParseHex("#00005050"), 1);
                        var pinkBrush     = Brushes.Solid(Rgba32.ParseHex("#C71585"));

                        var points = new List <PointF>();

                        for (int i = 1; i < width; i++)
                        {
                            var x = ScreenToX(i);
                            var y = MathF.Pow(x, 2) * MathF.Exp(x);

                            // Draw to screen
                            PointF point = new PointF(i, YToScreen(y));

                            // Eliminate out of bounds exception
                            if (
                                !float.IsInfinity(y) &&
                                MathF.Abs(y) < height * 10
                                )
                            {
                                points.Add(point);
                            }
                        }

                        DrawAxis(ctx, width, height);

                        ctx.DrawLines(blackPen, points.ToArray());
                    });

                    // Set the source
                    ImageControl.Source = Helpers.ImageToBitmap(image);
                }
            }
        }
        public void Draw()
        {
            if (ImageWrapper != null)
            {
                // Get size of the image
                var width  = (int)ImageWrapper.ActualWidth;
                var height = (int)ImageWrapper.ActualHeight;

                using (image = new Image <Rgba32>(width, height))
                {
                    // Draw triangle
                    image.Mutate((ctx) =>
                    {
                        offset = new PointF(width / 2, height / 2);

                        // Define pens and inks
                        var pinkPen       = Pens.Solid(Rgba32.ParseHex("#C0C0FF"), 2);
                        var greenPen      = Pens.Solid(Rgba32.ParseHex("#228B22"), 1);
                        var blackPen      = Pens.Solid(Rgba32.ParseHex("#000000"), 1);
                        var blackTransPen = Pens.Solid(Rgba32.ParseHex("#00005050"), 1);
                        var pinkBrush     = Brushes.Solid(Rgba32.ParseHex("#C71585"));

                        var points = new List <PointF>();

                        try
                        {
                            // Get parameter a
                            float a = float.Parse(ParamA.Text);
                            // Quality and scale
                            float quality = (float)ParamB.Value;
                            scale         = (float)ScaleSlider.Value;

                            if (AxisCheckbox.IsChecked == true)
                            {
                                DrawAxis(ctx, width, height);
                            }


                            for (float i = -MathF.PI; i < MathF.PI; i += quality)
                            {
                                // x = a(t^2 - 1) / (t^2 + 1), y = at(t^2 - 1) / (t^2 + 1), t- infinite, а > 0
                                // t = i
                                var t = i;

                                // Find coords
                                var x = (a * (MathF.Pow(t, 2) - 1)) / (MathF.Pow(t, 2) + 1);
                                var y = a * t * (MathF.Pow(t, 2) - 1) / (MathF.Pow(t, 2) + 1);

                                // Convert to screen space
                                x = XToScreen(x);
                                y = YToScreen(y);

                                // Draw on the screen
                                PointF point = new PointF(x, y);

                                // Eliminate out of bounds exception
                                if (
                                    !float.IsInfinity(y) &&
                                    MathF.Abs(y) < height &&
                                    !float.IsInfinity(x) &&
                                    MathF.Abs(x) < width
                                    )
                                {
                                    points.Add(point);
                                }
                            }

                            ctx.DrawLines(pinkPen, points.ToArray());
                        }
                        catch (Exception err)
                        {
                        }
                    });

                    // Set the source
                    ImageControl.Source = Helpers.ImageToBitmap(image);
                }
            }
        }
 /// <summary>
 /// Draws the text  using the supplied text options onto the image filled via the brush.
 /// </summary>
 /// <param name="source">The image processing context.</param>
 /// <param name="textOptions">The text rendering options.</param>
 /// <param name="text">The text to draw.</param>
 /// <param name="color">The color.</param>
 /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
 public static IImageProcessingContext DrawText(
     this IImageProcessingContext source,
     TextOptions textOptions,
     string text,
     Color color) =>
 source.DrawText(textOptions, text, Brushes.Solid(color), null);
        public void Draw()
        {
            if (ImageWrapper != null)
            {
                var width  = (int)ImageWrapper.ActualWidth;
                var height = (int)ImageWrapper.ActualHeight;

                using (image = new Image <Rgba32>(width, height))
                {
                    // Draw triangle
                    image.Mutate((x) =>
                    {
                        // Define pens and inks
                        var sss = new Pen(Rgba32.ParseHex("#FFC0CB"), 10, new float[] { 2f, 6f, 8f });

                        var pinkPen   = Pens.Solid(Rgba32.ParseHex("#FFC0CB"), 10);
                        var greenPen  = Pens.Solid(Rgba32.ParseHex("#228B22"), 10);
                        var blackPen  = Pens.Solid(Rgba32.ParseHex("#000000"), 10);
                        var pinkBrush = Brushes.Solid(Rgba32.ParseHex("#C71585"));


                        Image img = Image.Load("Resources\\cat.jpg");
                        img.Mutate((x) =>
                        {
                            x.Resize(
                                128,
                                (x.GetCurrentSize().Height / x.GetCurrentSize().Width) * 128);
                        });
                        var CatBrush = new ImageBrush(img);


                        // Draw a Line
                        x.DrawLines(pinkPen, new PointF[] {
                            new PointF(30, 30),
                            new PointF(100, 30)
                        });

                        // Draw a Triangle
                        x.FillPolygon(CatBrush, new PointF[] {
                            new PointF(50, 50),
                            new PointF(500, 30),
                            new PointF(555, 555),
                        });

                        // Draw a star x y numberofcorners innerradius outerradius
                        Star star       = new Star(50, 50, 5, 50, 100);
                        var staroutline = Outliner.GenerateOutline(star, 2, JointStyle.Round);
                        x.Fill(CatBrush, star);

                        // Draw an arc
                        var arc = new Polygon(new CubicBezierLineSegment(new PointF[] {
                            new PointF(10, 400),
                            new PointF(30, 10),
                            new PointF(240, 30),
                            new PointF(300, 400)
                        }));
                        x.Draw(blackPen, arc);

                        // Draw some Ellipse
                        var sector = new EllipsePolygon(200, 200, 10, 20).Scale(5);
                        x.Draw(blackPen, sector);
                    });

                    // Set the source
                    ImageControl.Source = Helpers.ImageToBitmap(image);
                }
            }
        }