Esempio n. 1
0
        }         //顺时针

        private void canvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            ptEnd = e.MouseDevice.GetPosition(canvas);
            PathGeometry g        = new PathGeometry();
            PointInfo    infoPrev = ptinfos.Last();
            Point        ptPrev   = infoPrev.pt;
            float        len      = 0;
            Point        pt1      = new Point();
            Point        pt2      = new Point();
            Vector       dir0     = infoPrev.dir;

            pt1 = ptPrev + dir0 * lw * -0.5 / infoPrev.len;
            pt2 = ptPrev + dir0 * lw * 0.5 / infoPrev.len;
            PathFigure pf = new PathFigure();

            pf.Segments.Add(new LineSegment(ptPrev, true));
            pf.Segments.Add(new LineSegment(pt1, true));
            pf.Segments.Add(new LineSegment(ptEnd, true));
            pf.Segments.Add(new LineSegment(pt2, true));
            pf.StartPoint = ptPrev;
            pf.IsClosed   = true;
            g.Figures.Add(pf);
            geo.AddGeometry(g);
            geos.Add(geo);
            GeometryDrawing drawing = new GeometryDrawing(Brushes.Transparent, new Pen(Brushes.Black, 1), g);
            DrawingContext  dc      = dv.RenderOpen();

            dc.DrawDrawing(drawing);
            dc.Close();
            bmp.Render(dv);

            PointInfo info = new PointInfo();

            info.pt            = ptEnd;
            info.len           = len;
            info.dir           = new Vector();
            info.perpendicular = new Vector();

            tiwp.Clear();
            tiwp.Add(Regconize());             //添加识别到的文字到控件
            ptinfos.Clear();
        }
Esempio n. 2
0
        private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            Point        pt   = e.GetPosition(canvas);
            Vector       dir  = new Vector();
            double       len  = 0.0;
            Vector       vdir = new Vector();
            PathGeometry g    = new PathGeometry();

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DrawingContext dc = dv.RenderOpen();
                if (ptinfos.Count == 1)
                {
                    Point pt1, pt2;
                    len = Math.Sqrt((pt.X - ptStart.X) * (pt.X - ptStart.X) + (pt.Y - ptStart.Y) * (pt.Y - ptStart.Y));
                    dir = ptStart - pt;
                    dir.Normalize();
                    vdir = Perpendicular(dir);
                    // dir1 = New Vector(0, 0) - dir0
                    pt1 = pt + vdir * lw * 0.5 / (double)len;
                    pt2 = pt + vdir * lw * -0.5 / (double)len;
                    PathFigure pf = new PathFigure();
                    pf.Segments.Add(new LineSegment(ptStart, true));
                    pf.Segments.Add(new LineSegment(pt1, true));
                    pf.Segments.Add(new LineSegment(pt2, true));
                    pf.StartPoint = ptStart;
                    pf.IsClosed   = true;
                    g.Figures.Add(pf);
                    geo.AddGeometry(g);
                }
                else if (ptinfos != null && ptinfos.Count > 0)
                {
                    PointInfo infoPrev = ptinfos.Last();
                    Point     ptPrev = infoPrev.pt;
                    Point     pt1, pt2, pt3, pt4;
                    len = Math.Sqrt((pt.X - ptPrev.X) * (pt.X - ptPrev.X) + (pt.Y - ptPrev.Y) * (pt.Y - ptPrev.Y));
                    dir = ptPrev - pt;
                    dir.Normalize();
                    Vector dir0 = infoPrev.perpendicular;
                    vdir = Perpendicular(dir);
                    pt1  = ptPrev + dir0 * lw * 0.5 / (double)infoPrev.len;
                    pt2  = ptPrev + dir0 * lw * -0.5 / (double)infoPrev.len;
                    pt3  = pt + vdir * lw * 0.5 / (double)len;
                    pt4  = pt + vdir * lw * -0.5 / (double)len;
                    PathFigure pf = new PathFigure();
                    pf.Segments.Add(new LineSegment(ptPrev, true));
                    pf.Segments.Add(new LineSegment(pt1, true));
                    pf.Segments.Add(new LineSegment(pt3, true));
                    pf.Segments.Add(new LineSegment(pt4, true));
                    pf.Segments.Add(new LineSegment(pt2, true));
                    pf.StartPoint = ptPrev;
                    pf.IsClosed   = true;
                    g.Figures.Add(pf);
                    geo.AddGeometry(g);
                }

                GeometryDrawing drawing = new GeometryDrawing(Brushes.Transparent, new Pen(Brushes.Black, 1), g);
                dc.DrawDrawing(drawing);
                dc.Close();
                bmp.Render(dv);

                PointInfo info;
                info.pt            = pt;
                info.dir           = dir;
                info.len           = (float)len;
                info.perpendicular = vdir;
                ptinfos.Add(info);
            }
        }