Ejemplo n.º 1
0
 private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
 {
     _currentDrawingType = DrawingType.Polygon;
     ResetButtonStyle();
     barButtonPolygon.ButtonStyle = BarButtonStyle.Check;
     currentMyPoly = new MyPoly() { MyPen = (Pen)(mypen.Clone()) };
 }
Ejemplo n.º 2
0
        private void DrawShapes(Graphics g)
        {
            try
            {
                string errMessage = "";
                //ListXMLShapes.Clear();
                XmlNodeList xml_lines,xml_arrows,xml_rects,xml_regions;
                XmlDocument xmlDoc = new XmlDocument();
                RecognizerInfo ri = RecognizerBusiness.Instance.GetRecognizerInfoByCameraId(ref errMessage, _cameraID);
                if (ri==null)
                {
                    //if (XtraMessageBox.Show("�Բ�����ʹ�õ���Ƭû�ж�Ӧ��ʶ����������ѡ", "��ʾ", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                    {
                        return;
                    }
                }
                string name = @"c:\" + ri.Id.ToString() + "." + _cameraID + "admin" + ".xml";
                xmlDoc.Load(@name);
                    //ֱ��
                xml_lines = xmlDoc.SelectSingleNode("/pr/cameras/camera/lines").ChildNodes;

                float xScale = (float)this.Width/_currentImage.Width ;
                float yScale =  (float)(this.Height)/_currentImage.Height;

                foreach (XmlNode lineitem in xml_lines)
                {

                    MyLine line = new MyLine();
                    line.MyPen = new Pen(Color.Red, 1);
                    XmlElement xe = (XmlElement)lineitem;
                    line.P1.X = Convert.ToInt32(xe.GetAttribute("X1"));
                    line.P1.X = (int)(line.P1.X * xScale);
                    line.P1.Y = Convert.ToInt32(xe.GetAttribute("Y1"));
                    line.P1.Y = (int)(line.P1.Y * yScale);
                    line.P2.X = Convert.ToInt32(xe.GetAttribute("X2"));
                    line.P2.X = (int)(line.P2.X * xScale);
                    line.P2.Y = Convert.ToInt32(xe.GetAttribute("Y2"));
                    line.P2.Y = (int)(line.P2.Y * yScale);
                    line.MyPen.Color = ColorTranslator.FromHtml(xe.GetAttribute("PenColor"));
                    line.MyPen.Width = Convert.ToInt32(xe.GetAttribute("PenWidth"));
                    g.DrawLine(line.MyPen, line.P1, line.P2);
                    //ListXMLShapes.Add(line);
                }
                //��ͷ
                xml_arrows = xmlDoc.SelectSingleNode("/pr/cameras/camera/arrows").ChildNodes;
                foreach (XmlNode arrowitem in xml_arrows)
                {

                    MyArrow arrow = new MyArrow();
                    arrow.MyPen = new Pen(Color.Red, 1);
                    XmlElement xa = (XmlElement)arrowitem;
                    arrow.P1.X = Convert.ToInt32(xa.GetAttribute("X1"));
                    arrow.P1.X = (int)(arrow.P1.X * xScale);
                    arrow.P1.Y = Convert.ToInt32(xa.GetAttribute("Y1"));
                    arrow.P1.Y = (int)(arrow.P1.Y * yScale);
                    arrow.P2.X = Convert.ToInt32(xa.GetAttribute("X2"));
                    arrow.P2.X = (int)(arrow.P2.X * xScale);
                    arrow.P2.Y = Convert.ToInt32(xa.GetAttribute("Y2"));
                    arrow.P2.Y = (int)(arrow.P2.Y * yScale);
                    arrow.MyPen.Color = ColorTranslator.FromHtml(xa.GetAttribute("PenColor"));
                    arrow.MyPen.Width = Convert.ToInt32(xa.GetAttribute("PenWidth"));
                    g.DrawLine(arrow.MyPen, arrow.P1, arrow.P2);
                    //ListXMLShapes.Add(arrow);
                }
                //����
                xml_rects = xmlDoc.SelectSingleNode("/pr/cameras/camera/rects").ChildNodes;
                foreach (XmlNode rectitem in xml_rects)
                {

                    MyRect rect = new MyRect();
                    rect.MyPen = new Pen(Color.Red, 1);
                    XmlElement xr = (XmlElement)rectitem;
                    rect.P1.X = Convert.ToInt32(xr.GetAttribute("X"));
                    rect.P1.X = (int)(rect.P1.X * xScale);
                    rect.P1.Y = Convert.ToInt32(xr.GetAttribute("Y"));
                    rect.P1.Y = (int)(rect.P1.Y * yScale);
                    rect.Width = Convert.ToInt32(xr.GetAttribute("W"));
                    rect.Width = (int)(rect.Width * xScale);
                    rect.Height = Convert.ToInt32(xr.GetAttribute("H"));
                    rect.Height = (int)(rect.Height * yScale);
                    rect.MyPen.Color = ColorTranslator.FromHtml(xr.GetAttribute("PenColor"));
                    rect.MyPen.Width = Convert.ToInt32(xr.GetAttribute("PenWidth"));
                    g.DrawRectangle(rect.MyPen,rect.P1.X,rect.P1.Y,rect.Width,rect.Height);
                    //ListXMLShapes.Add(rect);
                }
                //�����
                xml_regions = xmlDoc.SelectSingleNode("/pr/cameras/camera/regions").ChildNodes;
                foreach (XmlNode regionitem in xml_regions)
                {

                    MyPoly poly = new MyPoly();
                    poly.MyPen = new Pen(Color.Red, 1);
                    XmlElement xp = (XmlElement)regionitem;
                    poly.MyPen.Color = ColorTranslator.FromHtml(xp.GetAttribute("PenColor"));
                    poly.MyPen.Width = Convert.ToInt32(xp.GetAttribute("PenWidth"));
                    XmlNodeList pointlist = regionitem.ChildNodes;
                    foreach (XmlNode pitem in pointlist)
                    {
                        Point p = new Point();
                        XmlElement test = (XmlElement)pitem;
                        p.X = Convert.ToInt32(test.GetAttribute("X"));
                        p.X = (int)(p.X * xScale);
                        p.Y = Convert.ToInt32(test.GetAttribute("Y"));
                        p.Y = (int)(p.Y * yScale);
                        poly.ListPoint.Add(p);
                    }
                    //IsFinished=true
                    poly.IsFinished = true;
                    g.DrawPolygon(poly.MyPen, poly.ListPoint.ToArray());
                    //ListXMLShapes.Add(poly);
                }
            }
            catch (Exception)
            {

                ;
            }
        }
Ejemplo n.º 3
0
        private void pictureEdit1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if ((_currentDrawingType == DrawingType.Polygon)&&e.Button == MouseButtons.Left)
            {
                if (currentMyPoly.IsFinished==false)
                {
                    //因为双击之前会先执行两次单击,因此在双击前先删除多余的两次点信息
                    //
                    currentMyPoly.ListPoint.RemoveAt(currentMyPoly.ListPoint.Count-1);
                    currentMyPoly.ListPoint.RemoveAt(currentMyPoly.ListPoint.Count - 1);
                    currentMyPoly.ListPoint.Add(e.Location);
                    currentMyPoly.IsFinished = true;
                    //List是引用,不能直接赋值
                    List<Point> newPoints = new List<Point>(currentMyPoly.ListPoint.Count);
                    foreach (var newPoint in currentMyPoly.ListPoint)
                    {
                        newPoints.Add(newPoint);
                    }
                    MyPoly myPoly = new MyPoly { IsFinished = currentMyPoly.IsFinished, ListPoint = newPoints, MyPen = currentMyPoly.MyPen };
                    ListShapes.Add(myPoly);
                    currentMyPoly.ListPoint.Clear();
                    currentMyPoly.IsFinished = false;
                    DrawingShapes(ListShapes);
                }

            }
        }