Esempio n. 1
0
        public LinearLineSegment PolygonToDrawingLine(Geometry place, GeoArea drawingArea, double resolutionX, double resolutionY)
        {
            //NOTE: this doesn't handle holes if you add them to the end in the reverse order. Those must be handled by a function in ImageSharp.
            var typeConvertedPoints = place.Coordinates.Select(o => new SixLabors.ImageSharp.PointF((float)((o.X - drawingArea.WestLongitude) * (1 / resolutionX)), (float)((o.Y - drawingArea.SouthLatitude) * (1 / resolutionY))));
            LinearLineSegment part  = new LinearLineSegment(typeConvertedPoints.ToArray());
            var x = new SixLabors.ImageSharp.Drawing.Path();

            return(part);
        }
Esempio n. 2
0
        private void DrawLine(params PointF[] segments)
        {
            var prev = segments.First();
            var path = new Path(segments.Skip(1).Select(p => {
                var segment = new LinearLineSegment(prev, p);
                prev        = p;

                return(segment);
            }));

            drawables.Add(new PathDrawer {
                Path = path
            });
        }
Esempio n. 3
0
        public IPath PolygonToDrawingPolygon(Geometry place, GeoArea drawingArea, double resolutionX, double resolutionY)
        {
            var lineSegmentList = new List <LinearLineSegment>();

            NetTopologySuite.Geometries.Polygon p = (NetTopologySuite.Geometries.Polygon)place;
            var typeConvertedPoints = p.ExteriorRing.Coordinates.Select(o => new SixLabors.ImageSharp.PointF((float)((o.X - drawingArea.WestLongitude) * (1 / resolutionX)), (float)((o.Y - drawingArea.SouthLatitude) * (1 / resolutionY))));
            var path = new SixLabors.ImageSharp.Drawing.Path(new LinearLineSegment(typeConvertedPoints.ToArray())).AsClosedPath();

            foreach (var hole in p.InteriorRings)
            {
                typeConvertedPoints = hole.Coordinates.Select(o => new SixLabors.ImageSharp.PointF((float)((o.X - drawingArea.WestLongitude) * (1 / resolutionX)), (float)((o.Y - drawingArea.SouthLatitude) * (1 / resolutionY))));
                var tempHole = new SixLabors.ImageSharp.Drawing.Path(new LinearLineSegment(typeConvertedPoints.ToArray())).AsClosedPath();
                path = path.Clip(tempHole);
            }
            return(path);
        }
        public byte[] GenerateImage(out string code, int codeLength = 4)
        {
            //验证码
            code = RandomTool.CreatRandom58String(codeLength);

            var random = new Random();

            //验证码颜色集合
            Color[] colorArray =
            {
                Color.Black,
                Color.Red,
                Color.DarkBlue,
                Color.Green,
                Color.Orange,
                Color.Brown,
                Color.DarkCyan,
                Color.Purple,
                Color.Yellow,
                Color.Cyan
            };
            //验证码字体集合
            string[] fonts = { "fonts/Apalu-2.ttf",

                               "fonts/Arvo-Italic.ttf",
                               "fonts/brelaregular.ttf",
                               "fonts/ColorTube-2.ttf",
                               "fonts/LeagueGothic-Italic.ttf",
                               "fonts/Quantum-2.ttf" };
            var      width  = code.Length * 40;
            var      height = 64;

            byte[] buffer = null;
            using (MemoryStream ms = new MemoryStream())
                using (Image image = new Image <Rgba32>(width, height, Color.White))
                {
                    //绘制干扰线条
                    for (int i = 0; i < 2; i++)
                    {
                        var cindex = random.Next(9);//随机颜色索引值
                        int x1     = random.Next(image.Width);
                        int y1     = random.Next(image.Height);

                        int x2 = random.Next(image.Width);
                        int y2 = random.Next(image.Height);

                        int x3 = random.Next(image.Width);
                        int y3 = random.Next(image.Height);

                        int x4 = random.Next(image.Width);
                        int y4 = random.Next(image.Height);

                        int x5        = random.Next(image.Width);
                        int y5        = random.Next(image.Height);
                        var thickness = random.Next(2, 4);

                        var linerSegemnt = new LinearLineSegment(
                            new Vector2(x1, y1),
                            new Vector2(x2, y2),
                            new Vector2(x3, y3),
                            new Vector2(x4, y4),
                            new Vector2(x5, y5)
                            );
                        var color = colorArray[cindex];
                        var p     = new SixLabors.ImageSharp.Drawing.Path(linerSegemnt);
                        image.Mutate(x => x.Draw(color, thickness, p));
                    }

                    //绘制文字
                    for (int i = 0; i < code.Length; i++)
                    {
                        var cindex = random.Next(7); //随机颜色索引值
                        var findex = random.Next(6); //随机字体索引值

                        var fontSize = random.Next(35, 50);

                        FontCollection collection = new();
                        FontFamily     family     = collection.Add(fonts[findex]);
                        Font           font       = family.CreateFont(fontSize);


                        Color selectColor = colorArray[cindex];

                        //产生一个轻微的抖动
                        int shakeX = random.Next(-5, 15);
                        int shakeY = random.Next(-5, 25);

                        float  x         = 3 + (i * 30) + shakeX; //x坐标
                        float  y         = 0 + shakeY;            //Y坐标
                        string character = code.Substring(i, 1);  //绘制的字符

                        image.Mutate(opera => opera.DrawText(character, font, selectColor, new PointF(x, y)));
                    }
                    //在随机位置画背景点
                    for (int i = 0; i < 5; i++)
                    {
                        var cindex = random.Next(7);//随机颜色索引值
                        int x      = random.Next(image.Width);
                        int y      = random.Next(image.Height);
                    }

                    //绘制干扰点
                    for (int i = 0; i < 40; i++)
                    {
                        var cindex = random.Next(7);//随机颜色索引值
                        int x      = random.Next(image.Width);
                        int y      = random.Next(image.Height);

                        var rectangle = new  Rectangle(x, y, 1, 1);
                        var coloer    = colorArray[cindex];
                        image.Mutate(x => x.Draw(coloer, 4f, rectangle));
                    }

                    image.SaveAsBmp(ms);

                    buffer = ms.ToArray();
                }
            return(buffer);
        }
Esempio n. 5
0
        public Task <RGBPixel[, ]> GenPattern(ulong frame)
        {
            Color fb = this.Farbe;

            // Male nächste Iteration ins malbild.

            switch (this.Art)
            {
            case LinienTyp.Kreuz:
            {
                ulong  w  = (ulong)(frame * Geschwindigkeit) % 100;
                double wr = w / 100d * Math.PI;
                double ph = 2 * Math.PI / Anzahl;
                PointF mp = new PointF(sizex / 2f, sizey / 2f);
                _malbild.Mutate((IImageProcessingContext i) =>
                    {
                        try
                        {
                            i.Fill(Color.Black);
                            for (int l = 0; l < this.Anzahl; l++)
                            {
                                PointF pointF = new PointF(mp.X + (float)Math.Cos(wr + ph * l) * sizex, mp.Y + (float)Math.Sin(wr + ph * l) * sizey);
                                i.DrawLines(new ShapeGraphicsOptions()
                                {
                                    GraphicsOptions = { Antialias = false }
                                }, fb, this.N,
                                            mp, pointF);
                            }
                        }
                        catch (Exception e)
                        {
                            //HACK, TODO, geht nicht, wegen Bug in Bib.
                        }
                    });
            }
            break;

            case LinienTyp.Raute:
            {
                float w = 0.01f * ((ulong)(frame * Geschwindigkeit) % 100);
                _malbild.Mutate(i =>
                    {
                        i.Clear(Color.Black);
                        i.DrawLines(new ShapeGraphicsOptions()
                        {
                            GraphicsOptions = { Antialias = false }
                        }, fb, this.N,
                                    new PointF(sizex * w, 0),
                                    new PointF(sizex, sizey * w),
                                    new PointF(sizex * (1 - w), sizey),
                                    new PointF(0, sizey * (1 - w)),
                                    new PointF(sizex * w, 0));
                    });
            }
            break;

            default:
            case LinienTyp.RadarLR:
            case LinienTyp.RadarRL:
            {
                ulong koo = (ulong)(frame * Geschwindigkeit) % sizex;
                koo = (this.Art == LinienTyp.RadarRL)? sizex - koo - 1 : koo;
                _malbild.Mutate(i =>
                    {
                        i.Clear(Color.Black);
                        i.DrawLines(new ShapeGraphicsOptions()
                        {
                            GraphicsOptions = { Antialias = false }
                        },
                                    fb, this.N, new PointF((float)koo, 0), new PointF((float)koo, sizey - 1));
                    });
            }
            break;

            case LinienTyp.RadarRLR:
            {
                ulong koo = (ulong)(frame * Geschwindigkeit) % (sizex * 2);
                koo = (koo >= sizex)? sizex - (koo % sizex) - 1 : koo % sizex;
                ILineSegment s = new LinearLineSegment(new PointF((float)koo, 0), new PointF((float)koo, sizey - 1));
                IPath        p = new SixLabors.ImageSharp.Drawing.Path(s);
                _malbild.Mutate(i =>
                    {
                        i.Clear(Color.Black);
                        i.Draw(new ShapeGraphicsOptions()
                        {
                            GraphicsOptions = { Antialias = false }
                        },
                               fb, N, p);
                    });
            }
            break;

            case LinienTyp.RadarVO:
            case LinienTyp.RadarOV:
            case LinienTyp.RadarVOV:
                throw new NotImplementedException();
                break;
            }
            // Recycle deinen Puffer und übertrage das Bild dahin.
            for (int x = 0; x < sizex; x++)
            {
                for (int y = 0; y < sizey; y++)
                {
                    var pxl = _malbild[x, y];
                    pbuf[x, y] = new RGBPixel(pxl.R, pxl.G, pxl.B);
                }
            }

            if (this.Farbwechsel)
            {
                HSVPixel h = this.Farbe;
                h.H       += 1;
                this.Farbe = h;
            }
            return(Task.FromResult(pbuf));
        }