AddPolygon() public method

public AddPolygon ( Point points ) : void
points Point
return void
示例#1
0
        public static void DrawPolygon(Graphics graphics, Polygon pol, Brush brush, Pen pen, IViewport viewport)
        {
            if (pol.ExteriorRing == null) return;
            if (pol.ExteriorRing.Vertices.Count <= 2) return;

            //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
            var gp = new GraphicsPath();

            //Add the exterior polygon
            var points = GeometryRenderer.WorldToScreenGDI(pol.ExteriorRing, viewport);
            if (points.Length > 2)
                gp.AddPolygon(points);
            //Add the interior polygons (holes)
            foreach (LinearRing linearRing in pol.InteriorRings)
            {
                var interiorPoints = GeometryRenderer.WorldToScreenGDI(linearRing, viewport);
                if (interiorPoints.Length > 2)
                    gp.AddPolygon(interiorPoints);
            }

            if (gp.PointCount == 0) return;

            // Only render inside of polygon if the brush isn't null or isn't transparent
            if (brush != null && brush != Brushes.Transparent)
                graphics.FillPath(brush, gp);
            // Create an outline if a pen style is available
            if (pen != null)
                graphics.DrawPath(pen, gp);
        }
示例#2
0
		/// <summary>
		/// Renders a polygon to the map.
		/// </summary>
		/// <param name="g">Graphics reference</param>
		/// <param name="pol">Polygon to render</param>
		/// <param name="brush">Brush used for filling (null or transparent for no filling)</param>
		/// <param name="pen">Outline pen style (null if no outline)</param>
		/// <param name="clip">Specifies whether polygon clipping should be applied</param>
		/// <param name="map">Map reference</param>
		public static void DrawPolygon(System.Drawing.Graphics g, SharpMap.Geometries.Polygon pol, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, SharpMap.Map map)
		{
			if (pol.ExteriorRing == null)
				return;
			if (pol.ExteriorRing.Vertices.Count > 2)
			{
				//Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
				System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

				//Add the exterior polygon
				if (!clip)
					gp.AddPolygon(pol.ExteriorRing.TransformToImage(map));
				else
					gp.AddPolygon(clipPolygon(pol.ExteriorRing.TransformToImage(map), map.Size.Width, map.Size.Height));

				//Add the interior polygons (holes)
				for (int i = 0; i < pol.InteriorRings.Count; i++)
					if (!clip)
						gp.AddPolygon(pol.InteriorRings[i].TransformToImage(map));
					else
						gp.AddPolygon(clipPolygon(pol.InteriorRings[i].TransformToImage(map), map.Size.Width, map.Size.Height));

				// Only render inside of polygon if the brush isn't null or isn't transparent
				if (brush != null && brush != System.Drawing.Brushes.Transparent)
					g.FillPath(brush, gp);
				// Create an outline if a pen style is available
				if (pen != null)
					g.DrawPath(pen, gp);
			}
		}
示例#3
0
        /// <summary>
        /// Renders a polygon to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="pol">Polygon to render</param>
        /// <param name="brush">Brush used for filling (null or transparent for no filling)</param>
        /// <param name="pen">Outline pen style (null if no outline)</param>
        /// <param name="clip">Specifies whether polygon clipping should be applied</param>
        /// <param name="map">Map reference</param>
        public static void DrawPolygon(System.Drawing.Graphics g, IPolygon pol, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, SharpMap.Map map)
        {
            try
            {
                if (pol.Shell == null)
                {
                    return;
                }
                if (pol.Shell.Coordinates.Length > 2)
                {
                    //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
                    System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

                    //Add the exterior polygon
                    if (!clip)
                    {
                        gp.AddPolygon(Transform.TransformToImage(pol.Shell, map));
                    }
                    //gp.AddPolygon(LimitValues(Transform.TransformToImage(pol.Shell, map), extremeValueLimit));
                    else
                    {
                        gp.AddPolygon(clipPolygon(Transform.TransformToImage(pol.Shell, map), map.Size.Width, map.Size.Height));
                    }

                    //Add the interior polygons (holes)
                    for (int i = 0; i < pol.Holes.Length; i++)
                    {
                        if (!clip)
                        {
                            gp.AddPolygon(Transform.TransformToImage(pol.Holes[i], map));
                        }
                        //gp.AddPolygon(LimitValues(Transform.TransformToImage(pol.Holes[i], map), extremeValueLimit));
                        else
                        {
                            gp.AddPolygon(clipPolygon(Transform.TransformToImage(pol.Holes[i], map), map.Size.Width, map.Size.Height));
                        }
                    }

                    // Only render inside of polygon if the brush isn't null or isn't transparent
                    if (brush != null && brush != System.Drawing.Brushes.Transparent)
                    {
                        g.FillPath(brush, gp);
                    }
                    // Create an outline if a pen style is available
                    if (pen != null)
                    {
                        g.DrawPath(pen, gp);
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                log.WarnFormat("Error during rendering", e);
            }
            catch (OverflowException e)
            {
                log.WarnFormat("Error during rendering", e);
            }
        }
		/*
		 * GetPolygonGraphicsPath
		 */

		/// <summary>
		/// Gets the <see cref="T:GraphicsPath"/> for the polygon with the specified number of points.
		/// </summary>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <paramref name="vertextCount"/> is less than 3.
		/// </exception>
		public static GraphicsPath GetPolygonGraphicsPath(int vertexCount, Rectangle polygonBounds)
		{
			if (vertexCount < 3)
			{
				throw new ArgumentOutOfRangeException(
					"vertexCount",
					vertexCount,
					Properties.Resources.ArgumentOutOfRange_PolygonPoints
					);
			}

			PointF[] points = new PointF[vertexCount];

			int currentPoint = 0;

			double offset = 360.0 / (double)vertexCount;

			for (double angle = -90; currentPoint < vertexCount; angle += offset)
			{
				points[currentPoint++] = new PointF(
					(float)(polygonBounds.Left + (double)polygonBounds.Width / 2.0 + GetEllipseX(DegToRad(angle), (double)polygonBounds.Width / 2.0)),
					(float)(polygonBounds.Top + (double)polygonBounds.Height / 2.0 + GetEllipseY(DegToRad(angle), (double)polygonBounds.Height / 2.0))
					);
			}

			GraphicsPath gp = new GraphicsPath();
			gp.AddPolygon(points);

			return gp;
		}
示例#5
0
        public override void MouseDown(object sender, MouseEventArgs e) {

            if (e.Button == MouseButtons.Left) {
                isMouseDown = true;
                if (CurrentMarker == null && isBegin) {
                    GMapMarker marker = createMarker(rMap1.FromLocalToLatLng(e.X, e.Y));
                }
            } else if (e.Button == MouseButtons.Right) {
                if (isBegin) {
                    //统计设备
                    if(routes.Markers.Count<2)return;

                    List<PS_gt> gtlist = new List<PS_gt>();
                    List<sd_gt> sdlist = new List<sd_gt>();
                    int bl = 1000000;
                    using (GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath()) {
                        List<PointF> list = new List<PointF>();
                        foreach (PointLatLng pll in routes.Polygons[0].Points) {
                            list.Add(new PointF((float)pll.Lng * bl, (float)pll.Lat * bl));

                        }
                        gp.AddPolygon(list.ToArray());
                        Region r = new Region(gp);
                        
                        foreach (GMapOverlay lay in this.rMap1.Overlays) {
                            if (!lay.IsVisibile|| !(lay is LineOverlay)) continue;
                            LineOverlay lo = lay as LineOverlay;
                            foreach (GMapMarker m in lo.Markers) {
                                if (r.IsVisible(new PointF((float)m.Position.Lng * bl, (float)m.Position.Lat * bl))) {
                                    if(m.Tag is PS_gt)
                                        gtlist.Add(m.Tag as PS_gt);
                                    else if(m.Tag is sd_gt)
                                    {
                                        sdlist.Add(m.Tag as sd_gt);
                                    }
                                }

                            }
                        }
                    }
                    if (gtlist.Count>sdlist.Count)
                    {
                        frmQytj dlg = new frmQytj(gtlist);
                        dlg.StartPosition = FormStartPosition.CenterScreen;

                        dlg.Show(this.rMap1);
                    }
                    else
                    {
                        frmSdtj dlg = new frmSdtj(sdlist);
                        dlg.StartPosition = FormStartPosition.CenterScreen;

                        dlg.Show(this.rMap1);
                    }
                   
                   
                }
                isBegin = false;
            }
        }
示例#6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics myGraphics = e.Graphics;
            Pen myPen = new Pen(Color.Black, 1.0f);
            GraphicsPath gp = new GraphicsPath();
            Matrix RotationTransform;

            float centerX = this.Size.Width / 2f;
            float centerY = this.Size.Height / 2f;

            gp.AddPolygon(new PointF[] {
                new PointF(centerX, centerY - 5),
                new PointF(centerX-5, centerY + 5),
                new PointF(centerX+5, centerY + 5)
            });

            RotationTransform = new Matrix(1, 0, 0, 1, 0, 0); // rotation matrix
            PointF RotationPoint = new PointF(centerX, centerY); // rotation point
            RotationTransform.RotateAt(heading, RotationPoint);
            gp.Transform(RotationTransform);

            myGraphics.FillPath(myPen.Brush, gp);
            myGraphics.DrawPath(myPen, gp);
            myPen.Dispose();
            gp.Dispose();
        }
示例#7
0
        public TButton()
            : base()
        {

            Point[] pts = {   new Point(0, _buttonsize / 2 - 1), 
                              new Point(_buttonsize / 2 - 1, 0), 
                              new Point(_buttonsize , _buttonsize / 2 - 1), 
                              new Point(_buttonsize , _buttonsize / 2 + 2),
                              new Point(_buttonsize / 2 + 2, _buttonsize - 1),
                              new Point(_buttonsize / 2 - 1, _buttonsize - 1) };

            GraphicsPath p = new GraphicsPath();
            p.AddPolygon(pts);
            p.CloseFigure();
            p.FillMode = FillMode.Alternate;
            this.Region = new Region(p);

            ImageList = new System.Windows.Forms.ImageList();
            ImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
            ImageList.ImageSize = new System.Drawing.Size(_buttonsize, _buttonsize);


            ImageList.Images.Add(((System.Drawing.Image)(Resource1.ResourceManager.GetObject("diamond1"))));
            ImageList.Images.Add(((System.Drawing.Image)(Resource1.ResourceManager.GetObject("diamond1_down"))));
            ImageIndex = 0;

        }
示例#8
0
        public override void DrawYourSelf(Graphics graphics)
        {
            int i = 0;
            Point[] points = new Point[this.pointsList.Count];//(Point[])pointsList.ToArray(typeof(Point));
            foreach(Point _point in this.pointsList)
            {
                points[i] = _point;
                i++;
            }

            GraphicsPath path = new GraphicsPath();
            path.AddPolygon(points);
            path.Transform(this.TMatrix.TransformationMatrix);

            Pen pen = new Pen(this.BorderColor, this.BorderWidth);

            if (IS_FILLED)
            {
                SolidBrush brush = new SolidBrush(this.FillColor);
                graphics.FillPath(brush, path);
            }

            graphics.DrawPath(pen, path);

            if (this.Selected)
            {
                this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
                this.selectionUnit.DrawYourSelf(graphics);
            }
        }
示例#9
0
        public static Bitmap RotateImage(Image img, float theta)
        {
            Matrix matrix = new Matrix();
            matrix.Translate(img.Width / -2, img.Height / -2, MatrixOrder.Append);
            matrix.RotateAt(theta, new Point(0, 0), MatrixOrder.Append);
            using (GraphicsPath gp = new GraphicsPath())
            {
                gp.AddPolygon(new Point[] { new Point(0, 0), new Point(img.Width, 0), new Point(0, img.Height) });
                gp.Transform(matrix);
                PointF[] pts = gp.PathPoints;

                Rectangle bbox = BoundingBox(img, matrix);
                Bitmap bmpDest = new Bitmap(bbox.Width, bbox.Height);

                using (Graphics gDest = Graphics.FromImage(bmpDest))
                {
                    Matrix mDest = new Matrix();
                    mDest.Translate(bmpDest.Width / 2, bmpDest.Height / 2, MatrixOrder.Append);
                    gDest.Transform = mDest;
                    gDest.CompositingQuality = CompositingQuality.HighQuality;
                    gDest.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    gDest.DrawImage(img, pts);
                    return bmpDest;
                }
            }
        }
示例#10
0
        public static void DrawPolygon(System.Drawing.Graphics g, SqlGeometry geometry, ViewContext context, System.Drawing.Brush brush, System.Drawing.Pen pen)
        {
            if (geometry.STExteriorRing() == null)
            {
                return;
            }

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            System.Drawing.PointF[] exterior = new System.Drawing.PointF[(int)geometry.STExteriorRing().STNumPoints()];
            for (int i = 1; i <= (int)geometry.STExteriorRing().STNumPoints(); i++)
            {
                exterior[i - 1] = WorldtoMap((double)geometry.STExteriorRing().STPointN(i).STX, (double)geometry.STExteriorRing().STPointN(i).STY, context);
            }
            gp.AddPolygon(exterior);

            //TODO: Add interior rings

            if (brush != null && brush != System.Drawing.Brushes.Transparent)
            {
                g.FillPath(brush, gp);
            }

            if (pen != null)
            {
                g.DrawPath(pen, gp);
            }
        }
示例#11
0
 public System.Drawing.Bitmap SetCornerAlpha(System.Drawing.Bitmap pBit)
 {
     System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(pBit);
     new System.Drawing.SolidBrush(EdgeDisplay.alphaColor);
     System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
     System.Drawing.PointF[] array = new System.Drawing.PointF[4];
     array[0] = new System.Drawing.PointF(0f, 0f);
     array[1] = new System.Drawing.PointF(0f, (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)pBit.Height, (float)pBit.Height);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     array[0] = new System.Drawing.PointF((float)this.subSize.Width, 0f);
     array[1] = new System.Drawing.PointF((float)(this.subSize.Width - pBit.Height), (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)(this.subSize.Width + pBit.Height + 1), (float)pBit.Height);
     array[3] = new System.Drawing.PointF((float)(this.subSize.Width + 1), 0f);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     array[0] = new System.Drawing.PointF((float)(this.subSize.Width + this.subSize.Height), 0f);
     array[1] = new System.Drawing.PointF((float)(this.subSize.Width + this.subSize.Height - pBit.Height), (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)(this.subSize.Width + this.subSize.Height + pBit.Height + 1), (float)pBit.Height);
     array[3] = new System.Drawing.PointF((float)(this.subSize.Width + this.subSize.Height + 1), 0f);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     array[0] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height), 0f);
     array[1] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height - pBit.Height), (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height + pBit.Height + 1), (float)pBit.Height);
     array[3] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height + 1), 0f);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     array[0] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height * 2), 0f);
     array[1] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height * 2 - pBit.Height), (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height * 2 + pBit.Height + 1), (float)pBit.Height);
     array[3] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height * 2 + 1), 0f);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     return(pBit);
 }
 /// <summary>
 /// Initializes the <see cref="T:LinePenStyle"/> class.
 /// </summary>
 static LinePenStyle()
 {
     Point[] ps = new Point[3] { new Point(-2, 0), new Point(0, 4), new Point(2, 0) };
     GraphicsPath gpath = new GraphicsPath();
     gpath.AddPolygon(ps);
     gpath.CloseAllFigures();
     mGeneralizationCap = new CustomLineCap(null, gpath);
 }
示例#13
0
        public static void Paint( object sender)
        {
            Form form = ((Form)sender);
            List<Point> list = new List<Point>();
            int width = form.Width;
            int height = form.Height;

            //左上
            list.Add(new Point(0, 5));
            list.Add(new Point(1, 5));
            list.Add(new Point(1, 3));
            list.Add(new Point(2, 3));
            list.Add(new Point(2, 2));
            list.Add(new Point(3, 2));
            list.Add(new Point(3, 1));
            list.Add(new Point(5, 1));
            list.Add(new Point(5, 0));
            //右上
            list.Add(new Point(width - 5, 0));
            list.Add(new Point(width - 5, 1));
            list.Add(new Point(width - 3, 1));
            list.Add(new Point(width - 3, 2));
            list.Add(new Point(width - 2, 2));
            list.Add(new Point(width - 2, 3));
            list.Add(new Point(width - 1, 3));
            list.Add(new Point(width - 1, 5));
            list.Add(new Point(width - 0, 5));
            //右下
            list.Add(new Point(width - 0, height - 5));
            list.Add(new Point(width - 1, height - 5));
            list.Add(new Point(width - 1, height - 3));
            list.Add(new Point(width - 2, height - 3));
            list.Add(new Point(width - 2, height - 2));
            list.Add(new Point(width - 3, height - 2));
            list.Add(new Point(width - 3, height - 1));
            list.Add(new Point(width - 5, height - 1));
            list.Add(new Point(width - 5, height - 0));
            //左下
            list.Add(new Point(5, height - 0));
            list.Add(new Point(5, height - 1));
            list.Add(new Point(3, height - 1));
            list.Add(new Point(3, height - 2));
            list.Add(new Point(2, height - 2));
            list.Add(new Point(2, height - 3));
            list.Add(new Point(1, height - 3));
            list.Add(new Point(1, height - 5));
            list.Add(new Point(0, height - 5));

            Point[] points = list.ToArray();

            GraphicsPath shape = new GraphicsPath();
            shape.AddPolygon(points);

            //将窗体的显示区域设为GraphicsPath的实例
            form.Region = new System.Drawing.Region(shape);
        }
示例#14
0
        public static void Paint( object sender)
        {
            PictureBox pic = ((PictureBox)sender);
            List<Point> list = new List<Point>();
            int width = pic.Width;
            int height = pic.Height;

            //左上
            list.Add(new Point(0, 0));
            list.Add(new Point(0, 0));
            list.Add(new Point(0, 0));
            list.Add(new Point(0, 0));
            list.Add(new Point(0, 0));
            list.Add(new Point(0, 0));
            list.Add(new Point(0, 0));
            list.Add(new Point(0, 0));
            list.Add(new Point(0, 0));
            //右上
            list.Add(new Point(width - 0, 0));
            list.Add(new Point(width - 0, 0));
            list.Add(new Point(width - 0, 0));
            list.Add(new Point(width - 0, 0));
            list.Add(new Point(width - 0, 0));
            list.Add(new Point(width - 0, 0));
            list.Add(new Point(width - 0, 0));
            list.Add(new Point(width - 0, 0));
            list.Add(new Point(width - 0, 0));
            //右下
            list.Add(new Point(width - 0, height - 5));
            list.Add(new Point(width - 1, height - 5));
            list.Add(new Point(width - 1, height - 3));
            list.Add(new Point(width - 2, height - 3));
            list.Add(new Point(width - 2, height - 2));
            list.Add(new Point(width - 3, height - 2));
            list.Add(new Point(width - 3, height - 1));
            list.Add(new Point(width - 5, height - 1));
            list.Add(new Point(width - 5, height - 0));
            //左下
            list.Add(new Point(5, height - 0));
            list.Add(new Point(5, height - 1));
            list.Add(new Point(3, height - 1));
            list.Add(new Point(3, height - 2));
            list.Add(new Point(2, height - 2));
            list.Add(new Point(2, height - 3));
            list.Add(new Point(1, height - 3));
            list.Add(new Point(1, height - 5));
            list.Add(new Point(0, height - 5));

            Point[] points = list.ToArray();

            GraphicsPath shape = new GraphicsPath();
            shape.AddPolygon(points);

            //将窗体的显示区域设为GraphicsPath的实例
            pic.Region = new System.Drawing.Region(shape);
        }
示例#15
0
        public override RectangleF ReturnBounds()
        {
            Point[] points = (Point[])pointsList.ToArray(typeof(Point));
            GraphicsPath path = new GraphicsPath();

            path.AddPolygon(points);
            path.Transform(this.TMatrix.TransformationMatrix);

            return  path.GetBounds();
        }
示例#16
0
 public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath path)
 {
     if (pts != null)
     {
         if (pts.Length > 2)
         {
             path.AddPolygon(pts);
         }
     }
 }
示例#17
0
 public void Draw(Graphics g, Color c)
 {
     GraphicsPath path = new GraphicsPath();
     path.AddPolygon(m_HexagonPoints);
     using (SolidBrush brush = new SolidBrush(c))
     {
         g.FillPath(brush, path);
     }
     path.Dispose();
 }
示例#18
0
		public void FixtureSetUp ()
		{
			bitmap = new Bitmap (10, 10);
			graphic = Graphics.FromImage (bitmap);

			sp1 = new GraphicsPath ();
			sp1.AddPolygon (new Point[4] { new Point (0, 0), new Point (3, 0), new Point (3, 3), new Point (0, 3) });

			sp2 = new GraphicsPath ();
			sp2.AddPolygon (new Point[4] { new Point (2, 2), new Point (5, 2), new Point (5, 5), new Point (2, 5) });
		}
示例#19
0
        static Lanes()
        {
            TopLane = new GraphicsPath();
            TopLane.AddPolygon(_topLane.ToPointF());

            MidLane = new GraphicsPath();
            MidLane.AddPolygon(_midLane.ToPointF());

            BotLane = new GraphicsPath();
            BotLane.AddPolygon(_botLane.ToPointF());
        }
示例#20
0
        protected override void UpdatePath()
        {
            if (this.Points == null || this.Points.Length == 0) return;

            InternalPath = new GraphicsPath();
            InternalPath.AddPolygon(this.Points);

            Matrix mtx = new Matrix();
            mtx.RotateAt(this.Rotation, InternalRotationBasePoint);
            InternalPath.Transform(mtx);
        }
示例#21
0
文件: Figure.cs 项目: Asassin42/Kyrs
        public Region GetFigure()
        {
            var path = new GraphicsPath();

            path.AddPolygon(points);

            var region = new Region(path);
            path.Dispose();

            return region;
        }
示例#22
0
 /// <summary>
 /// Creates a triangle pattern
 /// </summary>
 /// <param name="x">The base length of the triangle</param>
 /// <param name="y">The location of the next triangle</param>
 /// <returns></returns>
 public static GraphicsPath GetTriangleSeries(float x, float y)
 {
     var gp = new GraphicsPath();
     gp.AddPolygon(new[] { new PointF(x, 0f), new PointF(0f, 0f), new PointF(0.5f*x, 2f*x/3f), new PointF(x, 0f) });
     gp.CloseFigure();
     
     //Just to move to a new position
     gp.AddEllipse(y, 0f, 0f, 0f);
     gp.CloseFigure();
     return gp;
 }
示例#23
0
		protected override GraphicsPath GeneratePath()
		{
			GraphicsPath path = new GraphicsPath();
			Point pt1 = new Point(
				Location.X + Size.Width / 2, Location.Y);
			Point pt2 = new Point(
				Location.X, Location.Y + Size.Height);
			Point pt3 = new Point(
				Location.X + Size.Width, Location.Y + Size.Height);
			path.AddPolygon(new Point[] { pt1, pt2, pt3 });
			return path;
		}
示例#24
0
 public override System.Drawing.Bitmap GetNext()
 {
     if (this.nowState == MarqueeDisplayState.First)
     {
         this.nowPositionF -= this.step;
         if (this.nowPositionF > (float)((this.newBitmap.Height + this.newBitmap.Width) / 2))
         {
             this.nowState = MarqueeDisplayState.Stay;
         }
         this.nowPosition = (int)this.nowPositionF;
         this.getPoint1(this.nowPosition);
         this.getPoint2(this.nowPosition);
         this.getPoint3(this.nowPosition);
         this.getPoint4(this.nowPosition);
         System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(this.newBitmap);
         System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
         System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
         graphicsPath.AddPolygon(this.pa1);
         graphics.SetClip(graphicsPath);
         graphics.Clear(System.Drawing.Color.Black);
         graphicsPath.ClearMarkers();
         graphicsPath.AddPolygon(this.pa2);
         graphics.SetClip(graphicsPath);
         graphics.Clear(System.Drawing.Color.Black);
         graphicsPath.ClearMarkers();
         graphicsPath.AddPolygon(this.pa3);
         graphics.SetClip(graphicsPath);
         graphics.Clear(System.Drawing.Color.Black);
         graphicsPath.ClearMarkers();
         graphicsPath.AddPolygon(this.pa4);
         graphics.SetClip(graphicsPath);
         graphics.Clear(System.Drawing.Color.Black);
         if (this.nowPositionF <= 0f)
         {
             this.nowState = MarqueeDisplayState.Second;
         }
         return(bitmap);
     }
     return(null);
 }
        public void CreateNewStarAnnotation()
        {
            // Create annotation group and add it to the chart annotations collection
            AnnotationGroup star = new AnnotationGroup();
            star.X = 20;
            star.Y = 20;
            star.Width = 30;
            star.Height = 20;
            star.AllowSelecting = true;
            star.AllowMoving = true;
            star.AllowResizing = true;

            Chart1.Annotations.Add(star);

            // Add star shaped polygon annotation into the group

            PointF[] starPolygon = new PointF[] {
                                                    new PointF(1,6), new PointF(27,23), new PointF(33,5), new PointF(44,22), new PointF(58,0),
                                                    new PointF(57,19), new PointF(75,11), new PointF(70,28), new PointF(100,37), new PointF(81,53),
                                                    new PointF(99,65), new PointF(75,67), new PointF(87,98), new PointF(63,69), new PointF(60,94),
                                                    new PointF(47,69), new PointF(34,100), new PointF(32,69), new PointF(23,74), new PointF(26,61),
                                                    new PointF(4,72), new PointF(22,49), new PointF(0,39), new PointF(23,32), new PointF(1,6) };

            GraphicsPath starPath = new GraphicsPath();

            starPath.AddPolygon(starPolygon);
            PolygonAnnotation poly = new PolygonAnnotation();
            poly.Name = "Star";
            poly.GraphicsPath = starPath;
            star.Annotations.Add(poly);

            // Set star polygon annotation position and appearance
            star.Annotations["Star"].X = 0;
            star.Annotations["Star"].Y = 0;
            star.Annotations["Star"].Width = 100;
            star.Annotations["Star"].Height = 100;
            star.Annotations["Star"].LineColor = Color.FromArgb(64,64,64);
            star.Annotations["Star"].BackColor = Color.FromArgb(220,255,255,192);
            star.Annotations["Star"].ShadowOffset = 2;

            // Add text in the middle of the star shape
            TextAnnotation textAnnotation = new TextAnnotation();
            textAnnotation.Name = "StarText";
            textAnnotation.Text = "New !!!";
            textAnnotation.X = 20;
            textAnnotation.Y = 20;
            textAnnotation.Width = 60;
            textAnnotation.Height = 60;
            star.Annotations.Add(textAnnotation);
            star.Annotations["StarText"].Font = new Font("MS Sans Serif", 10, FontStyle.Bold|FontStyle.Italic);
            star.Annotations["StarText"].ForeColor= Color.FromArgb(26, 59, 105);
        }
示例#26
0
        public GraphicsPath TristripToGraphicsPath()
        {
            GraphicsPath graphicsPath = new GraphicsPath();

            for (int i = 0; i < NofVertices - 2; i++)
            {
                graphicsPath.AddPolygon(new PointF[3]{ new PointF( (float)Vertex[i].X,   (float)Vertex[i].Y ),
				                                           new PointF( (float)Vertex[i+1].X, (float)Vertex[i+1].Y ),
				                                           new PointF( (float)Vertex[i+2].X, (float)Vertex[i+2].Y )  });
            }

            return graphicsPath;
        }
        public static GpcWrapper.Polygon ToGpcPolygon(UrbanChallenge.Common.Shapes.Polygon input)
        {
            GraphicsPath gp = new GraphicsPath();
            PointF[] polyPoints = new PointF[input.Count];

            for (int i = 0; i < input.Count; i++)
            {
                polyPoints[i] = DrawingUtility.ToPointF(input[i]);
            }

            gp.AddPolygon(polyPoints);
            return new GpcWrapper.Polygon(gp);
        }
示例#28
0
 public void Draw(Point cur)
 {
     switch (sh)
     {
         case Shape.pencil:
             g.DrawLine(pen, prev, cur);
             prev = cur;
             break;
         case Shape.rectangle:
             path = new GraphicsPath();
             if (prev.X > cur.X)
             {
                 if (prev.Y > cur.Y)
                     path.AddRectangle(new Rectangle(cur.X, cur.Y, prev.X - cur.X, prev.Y - cur.Y));
                 if (prev.Y < cur.Y)
                     path.AddRectangle(new Rectangle(cur.X, prev.Y, prev.X - cur.X, cur.Y - prev.Y));
             }
             else
             {
                 if ((prev.Y < cur.Y))
                     path.AddRectangle(new Rectangle(prev.X, prev.Y, cur.X - prev.X, cur.Y - prev.Y));
                 else
                     path.AddRectangle(new Rectangle(prev.X, cur.Y, cur.X - prev.X, prev.Y - cur.Y));
             }
             break;
         case Shape.circle:
             path = new GraphicsPath();
             path.AddEllipse(new Rectangle(prev.X, prev.Y, cur.X - prev.X, cur.Y - prev.Y));
             break;                   
         case Shape.line:
             path = new GraphicsPath();
             path.AddLine(prev, cur);
             break;                    
         case Shape.triangle:
             path = new GraphicsPath();
             Point[] pp = new Point[3];
             pp[0] = prev;
             pp[1] = cur;
             pp[2] = new Point(cur.X - 2 * (cur.X - prev.X), cur.Y);
             path.AddPolygon(pp);
             break;
         case Shape.erasor:
             path = null;
             g.DrawLine(er, prev, cur);
             prev = cur;
             break;
         default:
             break;
     }
     picture.Refresh();
 }
示例#29
0
 private void DrawGlow(Graphics g)
 {
     GraphicsPath p = new GraphicsPath();
     Point [] border = {
                         new Point(0			, 0			),
                         new Point(Width-1	, 0			),
                         new Point(Width-1	, Height-1	),
                         new Point(0			, Height-1	)
                     };
     p.AddPolygon(border);
     g.SmoothingMode = SmoothingMode.AntiAlias;
     g.DrawPath(new Pen(Color.Gold, 3), p);
     g.DrawPath(new Pen(Color.FromArgb(200, Color.White), 1), p);
 }
示例#30
0
        // draws link
        public void Draw(Graphics canvas)
        {
            Pen pen = new Pen(Color.Black, 1);

            // create arrow cap
            System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
            Point[] points = new Point[3];
            points[0] = new Point(0, 0);
            points[1] = new Point(-4, -7);
            points[2] = new Point(4, -7);
            graphicsPath.AddPolygon(points);
            pen.CustomEndCap = new System.Drawing.Drawing2D.CustomLineCap(graphicsPath, null);
            canvas.DrawLine(pen, from.Layout.X, from.Layout.Y, to.Layout.X, to.Layout.Y);
        }
示例#31
0
文件: Form1.cs 项目: humra/Practice
        private void Form1_Load(object sender, EventArgs e)
        {
            GraphicsPath gp = new GraphicsPath();
            Point[] points = new Point[3];

            points[0] = new Point(0, 0);
            points[1] = new Point(0, 300);
            points[2] = new Point(300, 300);

            gp.AddPolygon(points);
            this.AllowTransparency = true;

            this.Region = new Region(gp);
        }
示例#32
0
        protected override GraphicsPath GetPath()
        {
            GraphicsPath path = new GraphicsPath();
            PointF[] points = new PointF[4];

            points[0] = new PointF(Boundary.Left + Boundary.Width / 2.0f, Boundary.Top);
            points[1] = new PointF(Boundary.Right, Boundary.Top + Boundary.Height / 2.0f);
            points[2] = new PointF(Boundary.Left + Boundary.Width / 2.0f, Boundary.Bottom);
            points[3] = new PointF(Boundary.Left, Boundary.Top + Boundary.Height / 2.0f);

            path.AddPolygon(points);

            return path;
        }
 public override void Draw(Graphics g)
 {
     try
     {
         var path = new GraphicsPath();
         path.AddPolygon(PointFUtil.ToPointFArray(_rectangle.ToVertices()));
         if (this.FillBrush != null)
             g.FillPath(this.FillBrush, path);
         g.DrawPath(Pen, path);
     }
     catch (Exception)
     {
         //ignore
     }
 }
示例#34
0
    /*******************************/
    /// <summary>
    /// Creates a GraphicsPath from two Int Arrays with a specific number of points.
    /// </summary>
    /// <param name="xPoints">Int Array to set the X points of the GraphicsPath</param>
    /// <param name="yPoints">Int Array to set the Y points of the GraphicsPath</param>
    /// <param name="pointsNumber">Number of points to add to the GraphicsPath</param>
    /// <returns>A new GraphicsPath</returns>
    public static System.Drawing.Drawing2D.GraphicsPath CreateGraphicsPath(int[] xPoints, int[] yPoints, int pointsNumber)
    {
        System.Drawing.Drawing2D.GraphicsPath tempGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
        if (pointsNumber == 2)
            tempGraphicsPath.AddLine(xPoints[0], yPoints[0], xPoints[1], yPoints[1]);
        else
        {
            System.Drawing.Point[] tempPointArray = new System.Drawing.Point[pointsNumber];
            for (int index = 0; index < pointsNumber; index++)
                tempPointArray[index] = new System.Drawing.Point(xPoints[index], yPoints[index]);

            tempGraphicsPath.AddPolygon(tempPointArray);
        }
        return tempGraphicsPath;
    }
示例#35
0
        private void AddPolygon(IPolygon polygon, GraphicsPath graphicsPath)
        {
            if (polygon == null)
                throw new ArgumentNullException("polygon");

            ILineString exterior = polygon.ExteriorRing;
            IEnumerable<PointF> coords = this.GetCoords(exterior);
            graphicsPath.AddPolygon(coords.ToArray());

            foreach (ILineString ring in polygon.InteriorRings)
            {
                coords = this.GetCoords(ring);
                graphicsPath.AddPolygon(coords.ToArray());
            }
        }
示例#36
0
        public void SetPosition(float x, float y, int nWidth)
        {
            float nSideLength = (float)((float)nWidth * Tan30);
            m_HexagonPoints[0] = new Point((int)Math.Floor(x - (float)(nWidth / 2)), (int)Math.Floor(y - (nSideLength / 2))-1);
            m_HexagonPoints[1] = new Point((int)Math.Floor((float)x), (int)Math.Floor(y - (float)(nWidth / 2))-1);
            m_HexagonPoints[2] = new Point((int)Math.Floor(x + (float)(nWidth / 2)), (int)Math.Floor(y - (nSideLength / 2))-1);
            m_HexagonPoints[3] = new Point((int)Math.Floor(x + (float)(nWidth / 2)), (int)Math.Floor(y + (nSideLength / 2)) + 1);
            m_HexagonPoints[4] = new Point((int)Math.Floor((float)x), (int)Math.Floor(y + (float)(nWidth / 2)) + 1);
            m_HexagonPoints[5] = new Point((int)Math.Floor(x - (float)(nWidth / 2)), (int)Math.Floor(y + (nSideLength / 2)) + 1);

            GraphicsPath path = new GraphicsPath();
            path.AddPolygon(m_HexagonPoints);
            m_Bounds = Rectangle.Round(path.GetBounds());
            m_Bounds.Inflate(2, 2);
        }
示例#37
0
		static GraphicsPath InitializePath ()
		{
			GraphicsPath path = new GraphicsPath();
			path.StartFigure();
			path.AddPolygon(new PointF[]{
				new PointF(0.0f, 1.9f),
				new PointF(2.0f, 1.9f),
				new PointF(2.0f, 1.0f),
				new PointF(3.0f, 2.0f),
				new PointF(2.0f, 3.0f),
				new PointF(2.0f, 2.1f),
				new PointF(0.0f, 2.1f)
			});
			path.CloseFigure();
			path.StartFigure();
			path.AddPolygon(new PointF[]{
				new PointF(2.2f, 1.4f),
				new PointF(2.7f, 2.0f),
				new PointF(2.2f, 2.6f)
			});
			path.FillMode = FillMode.Alternate;
			path.CloseFigure();
			return path;
		}
示例#38
0
    /*******************************/
    /// <summary>
    /// Creates a GraphicsPath from two Int Arrays with a specific number of points.
    /// </summary>
    /// <param name="xPoints">Int Array to set the X points of the GraphicsPath</param>
    /// <param name="yPoints">Int Array to set the Y points of the GraphicsPath</param>
    /// <param name="pointsNumber">Number of points to add to the GraphicsPath</param>
    /// <returns>A new GraphicsPath</returns>
    public static System.Drawing.Drawing2D.GraphicsPath CreateGraphicsPath(int[] xPoints, int[] yPoints, int pointsNumber)
    {
        System.Drawing.Drawing2D.GraphicsPath tempGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
        if (pointsNumber == 2)
        {
            tempGraphicsPath.AddLine(xPoints[0], yPoints[0], xPoints[1], yPoints[1]);
        }
        else
        {
            System.Drawing.Point[] tempPointArray = new System.Drawing.Point[pointsNumber];
            for (int index = 0; index < pointsNumber; index++)
            {
                tempPointArray[index] = new System.Drawing.Point(xPoints[index], yPoints[index]);
            }

            tempGraphicsPath.AddPolygon(tempPointArray);
        }
        return(tempGraphicsPath);
    }
示例#39
0
        private void rectProgress_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);
            if (showDetails)
            {
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                Rectangle rc = rectProgress.Bounds;
                using (Pen the_pen = new Pen(colours[1, myProgressColour], 1))
                {
                    List <PointF> pnts = new List <PointF>();
                    pnts.Add(new PointF(rc.X, rc.Y));
                    pnts.Add(new PointF(rc.Width - 1.0f, rc.Y));
                    pnts.Add(new PointF(rc.Width - 1.0f, rc.Y + rc.Height));
                    pnts.Add(new PointF(rc.X, rc.Y + rc.Height));

                    // creates a  rectangle region, the line is too thick if Rectangle is used.
                    System.Drawing.Drawing2D.GraphicsPath rectanglePath1 = new System.Drawing.Drawing2D.GraphicsPath();
                    rectanglePath1.AddPolygon(new PointF[] { pnts[0], pnts[1], pnts[2], pnts[3] });
                    Region rectangleRegion1 = new Region(rectanglePath1);
                    e.Graphics.FillRegion(the_pen.Brush, rectangleRegion1);

                    the_pen.Color = Color.Red;
                    pnts.Clear();
                    pnts.Add(new PointF(rc.X + rc.Width - 1.0f, rc.Y));
                    pnts.Add(new PointF(rc.Width, rc.Y));
                    pnts.Add(new PointF(rc.Width, rc.Y + rc.Height));
                    pnts.Add(new PointF(rc.X + rc.Width - 1.0f, rc.Y + rc.Height));
                    System.Drawing.Drawing2D.GraphicsPath rectanglePath2 = new System.Drawing.Drawing2D.GraphicsPath();
                    rectanglePath2.AddPolygon(new PointF[] { pnts[0], pnts[1], pnts[2], pnts[3] });
                    Region rectangleRegion2 = new Region(rectanglePath2);
                    e.Graphics.FillRegion(the_pen.Brush, rectangleRegion2);

                    rectanglePath1.Dispose();
                    rectangleRegion1.Dispose();
                    rectanglePath2.Dispose();
                    rectangleRegion2.Dispose();

                    the_pen.Dispose();
                }
            }
        }
示例#40
0
        protected void drawRegion()
        {
            int          Chamfer = 2;
            List <Point> pnts    = new List <Point>();

            pnts.Add(new Point(Chamfer, 0));
            pnts.Add(new Point(this.Size.Width - Chamfer, 0));
            pnts.Add(new Point(this.Size.Width, Chamfer));
            pnts.Add(new Point(this.Size.Width, this.Size.Height - Chamfer));
            pnts.Add(new Point(this.Size.Width - Chamfer, this.Size.Height));
            pnts.Add(new Point(Chamfer, this.Size.Height));
            pnts.Add(new Point(0, this.Size.Height - Chamfer));
            pnts.Add(new Point(0, Chamfer));

            // creates a Hexagonal Form shape
            System.Drawing.Drawing2D.GraphicsPath octPath = new System.Drawing.Drawing2D.GraphicsPath();
            octPath.AddPolygon(new Point[] { pnts[0], pnts[1], pnts[2], pnts[3], pnts[4], pnts[5], pnts[6], pnts[7] });
            Region HexRegion = new Region(octPath);

            this.Region = HexRegion;
        }
示例#41
0
        public static void Paint(object sender, PaintEventArgs e)
        {
            if (Template.SmoothCorner)
            {
                Form form = (Form)sender;
                List <System.Drawing.Point> list = new List <System.Drawing.Point>();
                int width  = form.Width;
                int height = form.Height;
                list.Add(new System.Drawing.Point(0, 7));
                list.Add(new System.Drawing.Point(1, 6));
                list.Add(new System.Drawing.Point(1, 5));
                list.Add(new System.Drawing.Point(2, 4));
                list.Add(new System.Drawing.Point(3, 3));
                list.Add(new System.Drawing.Point(4, 2));
                list.Add(new System.Drawing.Point(5, 1));
                list.Add(new System.Drawing.Point(6, 1));
                list.Add(new System.Drawing.Point(7, 1));
                list.Add(new System.Drawing.Point(8, 0));
                list.Add(new System.Drawing.Point(width - 7, 0));
                list.Add(new System.Drawing.Point(width - 6, 1));
                list.Add(new System.Drawing.Point(width - 5, 1));
                list.Add(new System.Drawing.Point(width - 4, 2));
                list.Add(new System.Drawing.Point(width - 3, 2));
                list.Add(new System.Drawing.Point(width - 3, 3));
                list.Add(new System.Drawing.Point(width - 2, 3));
                list.Add(new System.Drawing.Point(width - 2, 5));
                list.Add(new System.Drawing.Point(width - 1, 5));
                list.Add(new System.Drawing.Point(width - 1, 6));
                list.Add(new System.Drawing.Point(width, height));
                list.Add(new System.Drawing.Point(0, height));
                System.Drawing.Point[] points = list.ToArray();
                System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
                graphicsPath.AddPolygon(points);
                form.Region = new System.Drawing.Region(graphicsPath);
                return;
            }
            Form form2 = (Form)sender;

            form2.Region = new System.Drawing.Region(new System.Drawing.Rectangle(0, 0, form2.Width, form2.Height));
        }
示例#42
0
 protected override System.Drawing.Region OnCreateMaskRegion(Skybound.VisualTips.VisualTip tip, Skybound.VisualTips.Rendering.VisualTipLayout layout)
 {
     if (RoundCorners)
     {
         System.Drawing.Rectangle rectangle = layout.WindowBounds;
         rectangle.Width++;
         rectangle.Height++;
         System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
         System.Drawing.Point[] pointArr = new System.Drawing.Point[8];
         pointArr[0] = new System.Drawing.Point(rectangle.X + 2, rectangle.Y);
         pointArr[1] = new System.Drawing.Point(rectangle.Right - 3, rectangle.Y);
         pointArr[2] = new System.Drawing.Point(rectangle.Right - 1, rectangle.Y + 2);
         pointArr[3] = new System.Drawing.Point(rectangle.Right - 1, rectangle.Bottom - 4);
         pointArr[4] = new System.Drawing.Point(rectangle.Right - 4, rectangle.Bottom - 1);
         pointArr[5] = new System.Drawing.Point(rectangle.X + 2, rectangle.Bottom - 1);
         pointArr[6] = new System.Drawing.Point(rectangle.X, rectangle.Bottom - 4);
         pointArr[7] = new System.Drawing.Point(rectangle.X, rectangle.Y + 2);
         graphicsPath.AddPolygon(pointArr);
         return(new System.Drawing.Region(graphicsPath));
     }
     return(base.OnCreateMaskRegion(tip, layout));
 }
示例#43
0
        private void SetFormCircle()
        {
            int radian = 4;           //圆弧角的比率,可以自己改变这个值看具体的效果
            int w      = this.Width;  //窗体宽
            int h      = this.Height; //窗体高

            //对于矩形的窗体,要在一个角上画个弧度至少需要2个点,所以4个角需要至少8个点
            Point p1 = new Point(radian, 0);
            Point p2 = new Point(w - radian, 0);
            Point p3 = new Point(w, radian);
            Point p4 = new Point(w, h - radian);
            Point p5 = new Point(w - radian, h);
            Point p6 = new Point(radian, h);
            Point p7 = new Point(0, h - radian);
            Point p8 = new Point(0, radian);

            System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();

            Point[] p = new Point[] { p1, p2, p3, p4, p5, p6, p7, p8 };
            shape.AddPolygon(p);

            //将窗体的显示区域设为GraphicsPath的实例
            this.Region = new System.Drawing.Region(shape);
        }
示例#44
0
        public override void Draw(Point p)
        {
            myRectangle = new Rectangle(p, mySize);

            int x1 = mySize.Width / 3 * 2;
            int x2 = mySize.Width;

            int y1 = mySize.Height / 5;
            int y2 = mySize.Height / 2;
            int y3 = mySize.Height / 5 * 4;
            int y4 = mySize.Height;

            myPoints[0] = new Point(p.X, p.Y + y1);
            myPoints[1] = new Point(p.X + x1, p.Y + y1);
            myPoints[2] = new Point(p.X + x1, p.Y);
            myPoints[3] = new Point(p.X + x2, p.Y + y2);
            myPoints[4] = new Point(p.X + x1, p.Y + y4);
            myPoints[5] = new Point(p.X + x1, p.Y + y3);
            myPoints[6] = new Point(p.X, p.Y + y3);

            gp.AddPolygon(myPoints);

            Refresh();
        }
示例#45
0
 public override System.Drawing.Bitmap GetNext()
 {
     System.Drawing.Bitmap result;
     lock (this.newBitmap)
     {
         lock (this.oldBitmap)
         {
             if (this.nowState == MarqueeDisplayState.First)
             {
                 this.nowPositionF -= this.step;
                 if (this.nowPositionF < 0f)
                 {
                     this.nowState = MarqueeDisplayState.Stay;
                 }
                 this.nowPosition = (int)this.nowPositionF;
                 this.getPoint1(this.nowPosition);
                 this.getPoint2(this.nowPosition);
                 this.getPoint3(this.nowPosition);
                 this.getPoint4(this.nowPosition);
             }
             else
             {
                 if (this.nowState == MarqueeDisplayState.Stay)
                 {
                     this.StayNum += 42;
                     if (this.StayNum > this.effect.Stay)
                     {
                         if (this.effect.ExitMode == 0)
                         {
                             result = null;
                             return(result);
                         }
                         this.nowState = MarqueeDisplayState.Exit;
                     }
                     result = new System.Drawing.Bitmap(this.newBitmap);
                     return(result);
                 }
                 if (this.nowState == MarqueeDisplayState.Exit)
                 {
                     result = this.Exit.GetNext();
                     return(result);
                 }
             }
             System.Drawing.Bitmap   bitmap    = new System.Drawing.Bitmap(this.oldBitmap);
             System.Drawing.Graphics graphics  = System.Drawing.Graphics.FromImage(bitmap);
             System.Drawing.Bitmap   image     = new System.Drawing.Bitmap(this.newBitmap);
             System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(image);
             System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
             graphicsPath.AddPolygon(this.pa1);
             graphics2.SetClip(graphicsPath);
             graphics2.Clear(System.Drawing.Color.Transparent);
             graphicsPath.ClearMarkers();
             graphicsPath.AddPolygon(this.pa2);
             graphics2.SetClip(graphicsPath);
             graphics2.Clear(System.Drawing.Color.Transparent);
             graphicsPath.ClearMarkers();
             graphicsPath.AddPolygon(this.pa3);
             graphics2.SetClip(graphicsPath);
             graphics2.Clear(System.Drawing.Color.Transparent);
             graphicsPath.ClearMarkers();
             graphicsPath.AddPolygon(this.pa4);
             graphics2.SetClip(graphicsPath);
             graphics2.Clear(System.Drawing.Color.Transparent);
             graphics.DrawImage(image, new System.Drawing.Point(0, 0));
             result = bitmap;
         }
     }
     return(result);
 }
示例#46
0
        /// <summary>
        /// 获取指定点位集合的图像
        /// </summary>
        /// <param name="orialbmp"></param>
        /// <param name="points"></param>
        /// <param name="bDisposeOrial"></param>
        /// <returns></returns>
        public static Bitmap GetRegionBitmap(Image orialbmp, Point[] points, bool bDisposeOrial = true)
        {
            if (orialbmp == null)
            {
                return(null);
            }
            if (points == null || points.Length == 0)
            {
                return((Bitmap)orialbmp);
            }

            try
            {
                if (points.Length == 2)
                {
                    Rectangle selection = new Rectangle(points[0].X, points[0].Y, Math.Abs(points[1].X - points[0].X),
                                                        Math.Abs(points[1].Y - points[0].Y));
                    Bitmap bmpNew = ((Bitmap)orialbmp).Clone(selection, orialbmp.PixelFormat);
                    if (bDisposeOrial)
                    {
                        orialbmp.Dispose();
                        orialbmp = null;
                    }
                    return(bmpNew);
                }
                else if (points.Length == 3)
                {
                    System.Drawing.Drawing2D.GraphicsPath lPath = new System.Drawing.Drawing2D.GraphicsPath();
                    lPath.AddPolygon(points);
                    Region region = new Region(new RectangleF(0, 0, orialbmp.Width, orialbmp.Height));
                    region.Xor(lPath);
                    Bitmap   bmpNew    = (Bitmap)orialbmp.Clone();
                    Graphics lGraphics = Graphics.FromImage(bmpNew);
                    lGraphics.FillRegion(Brushes.White, region);
                    lGraphics.Dispose();
                    if (bDisposeOrial)
                    {
                        orialbmp.Dispose();
                        orialbmp = null;
                    }
                    return(bmpNew);
                }
                else if (points.Length == 4)
                {
                    Rectangle selection = new Rectangle(points[0].X, points[0].Y, Math.Abs(points[3].X - points[0].X),
                                                        Math.Abs(points[3].Y - points[0].Y));
                    Bitmap bmpNew = ((Bitmap)orialbmp).Clone(selection, orialbmp.PixelFormat);
                    if (bDisposeOrial)
                    {
                        orialbmp.Dispose();
                        orialbmp = null;
                    }
                    return(bmpNew);
                }
            }
            catch (Exception ex1)
            {
                Log4NetHelper.Instance.Error("ImageHelper.GetRegionBitmap方法,截取局部图像区域出现错误:" + (ex1.InnerException == null? ex1.Message: ex1.InnerException.Message));
            }
            return(null);
        }
示例#47
0
        private void DrawAnalogBorder(Graphics g)
        {
            if (!AnalogDialRegionOnly)
            {
                g.FillRectangle(new SolidBrush(this.BackColor), 0, 0, this.Width, this.Height);
            }

            double DegStep = (DegHigh * 1.05 - DegLow / 1.05) / 19;
            double i = DegHigh * 1.05;
            double SinI, CosI;

            PointF[] curvePoints = new PointF[40];
            for (int cp = 0; cp < 20; cp++)
            {
                i                    = i - DegStep;
                SinI                 = Math.Sin(i);
                CosI                 = Math.Cos(i);
                curvePoints[cp]      = new PointF((float)(SinI * this.Width * 0.7 + this.Width / 2), (float)(CosI * this.Width * 0.7 + this.Height * 0.9));
                curvePoints[38 - cp] = new PointF((float)(SinI * this.Width * 0.3 + this.Width / 2), (float)(CosI * this.Width * 0.3 + this.Height * 0.9));
            }
            curvePoints[39] = curvePoints[0];
            System.Drawing.Drawing2D.GraphicsPath dialPath = new System.Drawing.Drawing2D.GraphicsPath();
            if (AnalogDialRegionOnly)
            {
                dialPath.AddPolygon(curvePoints);
            }
            else
            {
                dialPath.AddRectangle(new Rectangle(0, 0, this.Width, this.Height));
            }
            this.Region = new System.Drawing.Region(dialPath);
            g.FillPolygon(new SolidBrush(DialBackColor), curvePoints);

            // Test moving this block
            if (!UseLedLightInAnalog)
            {
                DegStep = (DegHigh - DegLow) / (LedCount1 + LedCount2 + LedCount3 - 1);
                int lc             = 0;
                int LedRadiusStart = (int)(this.Width * 0.6);
                if (!ShowTextInDial)
                {
                    LedRadiusStart = (int)(this.Width * 0.65);
                }
                for (i = DegHigh; i > DegLow - DegStep / 2; i = i - DegStep)
                {
                    //Graphics scale = g.Graphics;
                    Pen scalePen = new Pen(Led3ColorOn, Led.Width);
                    if (lc < LedCount1 + LedCount2)
                    {
                        scalePen = new Pen(Led2ColorOn, Led.Width);
                    }
                    if (lc < LedCount1)
                    {
                        scalePen = new Pen(Led1ColorOn, Led.Width);
                    }
                    lc++;
                    SinI = Math.Sin(i);
                    CosI = Math.Cos(i);
                    g.DrawLine(scalePen, (int)((LedRadiusStart - Led.Height) * SinI + this.Width / 2),
                               (int)((LedRadiusStart - Led.Height) * CosI + this.Height * 0.9),
                               (int)(LedRadiusStart * SinI + this.Width / 2), (int)(LedRadiusStart * CosI + this.Height * 0.9));
                    scalePen.Dispose();
                }
            }
            StringFormat format = new StringFormat();

            format.Alignment     = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            float MeterFontSize = this.Font.SizeInPoints;

            if (this.Width > 0)
            {
                MeterFontSize = MeterFontSize * (float)(this.Width / 100f);
            }
            if (MeterFontSize < 4)
            {
                MeterFontSize = 4;
            }
            if (MeterFontSize > 72)
            {
                MeterFontSize = 72;
            }
            Font MeterFont = new Font(this.Font.FontFamily, MeterFontSize);

            g.DrawString(this.MeterText, MeterFont, new SolidBrush(this.ForeColor), this.Width / 2, this.Height * 0.43f, format);

            if (ShowDialText)
            {
                double DialTextStep = (DegHigh - DegLow) / (DialText.Length - 1);
                int    dt           = 0;
                MeterFontSize = MeterFontSize * 0.6f;
                int TextRadiusStart = (int)(this.Width * 0.64);
                for (i = DegHigh; i > DegLow - DialTextStep / 2; i = i - DialTextStep)
                {
                    //Graphics scale = g.Graphics;
                    Brush        dtColor  = new SolidBrush(DialTextHigh);
                    StringFormat dtformat = new StringFormat();
                    dtformat.Alignment     = StringAlignment.Center;
                    dtformat.LineAlignment = StringAlignment.Center;
                    try
                    {
                        if (int.Parse(DialText[dt]) < 0)
                        {
                            dtColor = new SolidBrush(DialTextLow);
                        }
                        if (int.Parse(DialText[dt]) == 0)
                        {
                            dtColor = new SolidBrush(DialTextNeutral);
                        }
                    }
                    catch
                    {
                        dtColor = new SolidBrush(DialTextHigh);
                    }
                    Font dtfont = new Font(this.Font.FontFamily, MeterFontSize);
                    SinI = Math.Sin(i);
                    CosI = Math.Cos(i);
                    g.DrawString(DialText[dt++], dtfont, dtColor, (int)(TextRadiusStart * SinI + this.Width / 2), (int)(TextRadiusStart * CosI + this.Height * 0.9), dtformat);
                }
            }
        }