private void DrawTile(int x, int y, int width, int height, System.Drawing.Pen pen, MapOrientation oriention = MapOrientation.Isometric) { if (oriention == MapOrientation.Orthogonal) { var rect = new System.Drawing.Rectangle(x, y, width, height); gfx.DrawRectangle(pen, rect); } else { float x1 = x; float x2 = x + width / 2; float x3 = x + width; float y1 = y; float y2 = y + height / 2; float y3 = y + height; System.Drawing.PointF[] poly = new System.Drawing.PointF[5]; poly[0].X = x1; poly[0].Y = y2; poly[1].X = x2; poly[1].Y = y1; poly[2].X = x3; poly[2].Y = y2; poly[3].X = x2; poly[3].Y = y3; poly[4].X = x1; poly[4].Y = y2; gfx.DrawPolygon(pen, poly); } }
public override void DrawPolygon(CommonGui.Drawing.Pen pen, params Vector2f[] points) { System.Drawing.PointF[] points2 = points.Select(p => new System.Drawing.PointF(p.X, p.Y)).ToArray(); using (System.Drawing.Pen pen2 = CreatePen(pen)) { InternalGraphics.DrawPolygon(pen2, points2); } }
private static void RenderShape(GH_Canvas canvas, System.Drawing.Graphics graphics, System.Drawing.PointF[] points, System.Drawing.Color color) { int alpha = GH_Canvas.ZoomFadeMedium; float x0 = points[0].X; float x = x0; float y0 = points[0].Y; float y = y0; int arg_32_0 = 1; int num = points.Length - 1; for (int i = arg_32_0; i <= num; i++) { x0 = System.Math.Min(x0, points[i].X); x = System.Math.Max(x, points[i].X); y0 = System.Math.Min(y0, points[i].Y); y = System.Math.Max(y, points[i].Y); } System.Drawing.RectangleF bounds = System.Drawing.RectangleF.FromLTRB(x0, y0, x, y); bounds.Inflate(1f, 1f); System.Drawing.Drawing2D.LinearGradientBrush fill = new System.Drawing.Drawing2D.LinearGradientBrush(bounds, color, GH_GraphicsUtil.OffsetColour(color, 50), System.Drawing.Drawing2D.LinearGradientMode.Vertical); fill.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY; graphics.FillPolygon(fill, points); fill.Dispose(); if (alpha > 0) { System.Drawing.Color col0 = System.Drawing.Color.FromArgb(System.Convert.ToInt32(0.5 * (double)alpha), System.Drawing.Color.White); System.Drawing.Color col = System.Drawing.Color.FromArgb(0, System.Drawing.Color.White); System.Drawing.Drawing2D.LinearGradientBrush highlightFill = new System.Drawing.Drawing2D.LinearGradientBrush(bounds, col0, col, System.Drawing.Drawing2D.LinearGradientMode.Vertical); highlightFill.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY; System.Drawing.Pen highlightEdge = new System.Drawing.Pen(highlightFill, 3f); highlightEdge.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; highlightEdge.CompoundArray = new float[] { 0f, 0.5f }; graphics.DrawPolygon(highlightEdge, points); highlightFill.Dispose(); highlightEdge.Dispose(); } graphics.DrawPolygon(new System.Drawing.Pen(color, 1f) { LineJoin = System.Drawing.Drawing2D.LineJoin.Round }, points); }
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { System.Drawing.Point[] points = new System.Drawing.Point[nPoints]; for (int i = 0; i < nPoints; i++) { points[i] = new System.Drawing.Point(xPoints[i], yPoints[i]); } nativeGraphics.DrawPolygon(stroke.pen, points); }
public void DrawPolygon(Polygon poly, float w) { var points = new System.Drawing.PointF[poly.Points.Count]; for (var i = 0; i < points.Length; i++) { points[i] = new System.Drawing.PointF(poly.Points[i].X, poly.Points[i].Y); } g.DrawPolygon(color.GetPen(w), points); }
public void DrawPolygon(System.Drawing.Point[] points, bool fill = false) { System.Drawing.Graphics g = this; System.Drawing.Point[] screenPoints = viewportToScreen(points); g.DrawPolygon(CurrentPen as System.Drawing.Pen, screenPoints); if (fill) { g.FillPolygon(CurrentBrush as System.Drawing.Brush, screenPoints); } }
public override void Draw(Graphics g) { base.Draw(g); if (Annotation.Polygon.Length == 0) return; var sortedPolyIndices = this.Annotation.Polygon.SortPointsClockwise(); var poly = Annotation.Polygon.GetAt(sortedPolyIndices); var pictureBoxPoly = poly .Select(x => Element.ToPictureBoxCoordinate(x.ToPt())) .ToArray(); g.DrawPolygon(Pen, pictureBoxPoly); }
public override void Draw(Graphics g) { base.Draw(g); if (Annotation.Polygon.Length == 0) { return; } var sortedPolyIndices = this.Annotation.Polygon.SortPointsClockwise(); var poly = Annotation.Polygon.GetAt(sortedPolyIndices); var pictureBoxPoly = poly .Select(x => Element.ToPictureBoxCoordinate(x.ToPt())) .ToArray(); g.DrawPolygon(Pen, pictureBoxPoly); }
public void DrawPolygon(Point[] points, UInt32?edgeColor = null, UInt32?fillColor = null) { System.Drawing.Graphics g = this; System.Drawing.Point[] screenPoints = viewportToScreen(points); System.Drawing.Pen p = CurrentPen as System.Drawing.Pen; if (edgeColor != null) { p = new System.Drawing.Pen(ToSysColor(edgeColor)); } g.DrawPolygon(p, screenPoints); if (fillColor != null) { System.Drawing.Brush b = new System.Drawing.SolidBrush(ToSysColor(fillColor)); g.FillPolygon(b, screenPoints); } }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine(s_usage); return; } // [START vision_face_detection_tutorial_client] var client = ImageAnnotatorClient.Create(); // [END vision_face_detection_tutorial_client] // [START vision_face_detection_tutorial_send_request] var response = client.DetectFaces(Image.FromFile(args[0])); // [END vision_face_detection_tutorial_send_request] int numberOfFacesFound = 0; // [START vision_face_detection_tutorial_process_response] using (var image = System.Drawing.Image.FromFile(args[0])) using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image)) { var cyanPen = new System.Drawing.Pen(System.Drawing.Color.Cyan, 3); foreach (var annotation in response) { g.DrawPolygon(cyanPen, annotation.BoundingPoly.Vertices.Select( (vertex) => new System.Drawing.Point(vertex.X, vertex.Y)).ToArray()); // [START_EXCLUDE] numberOfFacesFound++; // [END_EXCLUDE] } // [START_EXCLUDE] int lastDot = args[0].LastIndexOf('.'); string outFilePath = lastDot < 0 ? args[0] + ".faces" : args[0].Substring(0, lastDot) + ".faces" + args[0].Substring(lastDot); image.Save(outFilePath); // [END_EXCLUDE] } // [END vision_face_detection_tutorial_process_response] // [START_EXCLUDE] Console.WriteLine($"Found {numberOfFacesFound} " + $"face{(numberOfFacesFound == 1 ? string.Empty : "s")}."); // [END_EXCLUDE] }
public override void Draw(System.Drawing.Graphics g) { if (g == null) { throw new System.ArgumentNullException("g"); } if (_points.Count > 0) { System.Drawing.Point[] points = GetViewportPoints(_points.Count + 1); points[points.Length - 1] = _viewportMousePosition; if (_closePath) { if (base.Brush != null) { System.Drawing.Drawing2D.Matrix prevBrushMatrix = PathVObjectCreateDesigner.AdaptBrushToViewport(base.Brush, this.VObjectHost.HostViewer); try { g.FillPolygon(base.Brush, points, _fillMode); } finally { if (prevBrushMatrix != null) { VObjectsUtils.SetBrushMatrix(base.Brush, prevBrushMatrix); } } } if (base.Pen != null) { g.DrawPolygon(base.CreateViewportPen(), points); } } else { if (base.Pen != null) { g.DrawLines(base.CreateViewportPen(), points); } } } }
// implement Draw() (step 5) public void Draw(System.Drawing.Graphics image) { System.Drawing.Brush brush = new System.Drawing.SolidBrush(color); System.Drawing.Pen pen = new System.Drawing.Pen(color); // Determine if circle, since use [upperLeft, width, height, !vertices] only if (name.Equals("Circle")) { image.DrawEllipse(pen, UpperLeft.X, UpperLeft.Y, Height, Width); image.FillEllipse(brush, new System.Drawing.Rectangle(UpperLeft.X, UpperLeft.Y, Width, Height)); } else { image.DrawPolygon(pen, Vertices); image.FillPolygon(brush, Vertices); } brush.Dispose(); pen.Dispose(); }
public override void Draw(System.Drawing.Graphics g) { if (g == null) { throw new System.ArgumentNullException("g"); } if (_points.Count > 1) { using (System.Drawing.Pen pen = CreateViewportPen()) { System.Drawing.Point[] points = (System.Drawing.Point[])_points.ToArray(typeof(System.Drawing.Point)); if (_closePath) { if (base.Brush != null) { System.Drawing.Drawing2D.Matrix prevBrushMatrix = PathVObjectCreateDesigner.AdaptBrushToViewport(base.Brush, base.VObjectHost.HostViewer); try { g.FillPolygon(base.Brush, points, _fillMode); } finally { if (prevBrushMatrix != null) { VObjectsUtils.SetBrushMatrix(base.Brush, prevBrushMatrix); } } } g.DrawPolygon(pen, points); } else { g.DrawLines(pen, points); } } } }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine(s_usage); return; } // [END main] // [START get_vision_service] var client = ImageAnnotatorClient.Create(); // [END get_vision_service] // [START detect_face] var response = client.DetectFaces(Image.FromFile(args[0])); // [END detect_face] // [START highlight_faces] var image = System.Drawing.Image.FromFile(args[0]); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image)) { var cyanPen = new System.Drawing.Pen(System.Drawing.Color. FromKnownColor(System.Drawing.KnownColor.Cyan), 3); foreach (var annotation in response) { g.DrawPolygon(cyanPen, annotation.BoundingPoly.Vertices.Select( (vertex) => new System.Drawing.Point(vertex.X, vertex.Y)).ToArray()); } } // [END highlight_faces] int lastDot = args[0].LastIndexOf('.'); string outFilePath = lastDot < 0 ? args[0] + ".faces" : args[0].Substring(0, lastDot) + ".faces" + args[0].Substring(lastDot); image.Save(outFilePath); }
public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper) { if (g == null) { throw new System.ArgumentNullException("g"); } if (coordinateMapper == null) { throw new System.ArgumentNullException("coordinateMapper"); } // FillPath doesn't support specifying FillMode, it always uses FillMode.Alternate, // so we have to use Graphics.FillPolygon method in other cases. if (!_closePath || base.Brush == null || _fillMode == System.Drawing.Drawing2D.FillMode.Alternate) { base.Draw(renderingRect, g, coordinateMapper); } else { System.Drawing.PointF[] transformedPoints = VObjectsUtils.TransformPoints(base.Transform, _points); for (int i = 0; i < transformedPoints.Length; i++) { transformedPoints[i] = coordinateMapper.WorkspaceToControl(transformedPoints[i], Aurigma.GraphicsMill.Unit.Point); } System.Drawing.Drawing2D.SmoothingMode oldSmoothingMode = g.SmoothingMode; System.Drawing.Pen pen = base.CreateViewportPen(coordinateMapper); try { switch (base.DrawMode) { case VObjectDrawMode.Draft: g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; break; case VObjectDrawMode.Normal: g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; break; default: throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("ExStrUnexpectedDrawMode")); } if (base.Brush != null) { AdaptBrushToViewport(coordinateMapper); try { g.FillPolygon(base.Brush, transformedPoints, _fillMode); } finally { RestoreBrush(); } } if (pen != null) { g.DrawPolygon(pen, transformedPoints); } } finally { pen.Dispose(); g.SmoothingMode = oldSmoothingMode; } } }
public void Draw(System.Drawing.Graphics g) { g.DrawPolygon(polygon.pen, polygon.points.ToArray()); }
private void RenderMesh() { if (_TextureCoordinates == null) { return; } double minx = 1.0, maxx = 0, miny = 1, maxy = 0; for (int i = 0; i < _TextureCoordinates.Count; i++) { if (_TextureCoordinates[i].X < minx) { minx = _TextureCoordinates[i].X; } if (_TextureCoordinates[i].Y < miny) { miny = _TextureCoordinates[i].Y; } if (_TextureCoordinates[i].X > maxx) { maxx = _TextureCoordinates[i].X; } if (_TextureCoordinates[i].Y > maxy) { maxy = _TextureCoordinates[i].Y; } } //2. normalize int width = (int)((maxx - minx) * 1920) + 1; int height = (int)((maxy - miny) * 1080) + 1; List <System.Drawing.PointF> meshpoints = new List <System.Drawing.PointF>(); for (int i = 0; i < _TextureCoordinates.Count; i++) { meshpoints.Add(new System.Drawing.PointF((float)(_TextureCoordinates[i].X - minx) * 1920, (float)(_TextureCoordinates[i].Y - miny) * 1080) ); } ////The bitmap must have ARGB Pixel format to support transparency System.Drawing.Bitmap bm = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); /////////////////////////////////////////////////////// System.Drawing.Graphics gbm = System.Drawing.Graphics.FromImage(bm); gbm.Clear(System.Drawing.Color.Transparent); //Draw the points System.Drawing.Brush brush; for (int i = 0; i < _TextureCoordinates.Count; i++) { FacePointMapping mapping = _Mappings.Find(p => p.index == i); brush = (mapping.side == "R") ? System.Drawing.Brushes.Red : System.Drawing.Brushes.Blue; if (mapping.side == "C") { brush = System.Drawing.Brushes.Cyan; } gbm.FillRectangle(brush, new System.Drawing.RectangleF( meshpoints[i].X, meshpoints[i].Y, 3, 3)); } if ((bool)chkMesh.IsChecked) { for (int i = 0; i < _TriangleIndices.Count; i = i + 3) { System.Drawing.Pen pen = new System.Drawing.Pen(_MeshColor); System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Color.FromArgb(255, System.Drawing.Color.YellowGreen)); //Use different pen for these triangles connected to these points //10 (center of base of upper lip) if (_TriangleIndices[i] == 10 || _TriangleIndices[i + 1] == 10 || _TriangleIndices[i + 2] == 10) { pen = pen2; } //14 (nose tip) if (_TriangleIndices[i] == 14 || _TriangleIndices[i + 1] == 14 || _TriangleIndices[i + 2] == 14) { pen = pen2; } //0 (chin) if (_TriangleIndices[i] == 0 || _TriangleIndices[i + 1] == 0 || _TriangleIndices[i + 2] == 0) { pen = pen2; } //328-1105 (right eye is between this 2 points) if (_TriangleIndices[i] == 1105 || _TriangleIndices[i + 1] == 1105 || _TriangleIndices[i + 2] == 1105) { pen = pen2; } //883-1092 (left eye is between these 2 points) if (_TriangleIndices[i] == 1092 || _TriangleIndices[i + 1] == 1092 || _TriangleIndices[i + 2] == 1092) { pen = pen2; } if (CCommon.ArePointsClockwise( meshpoints[_TriangleIndices[i]], meshpoints[_TriangleIndices[i + 1]], meshpoints[_TriangleIndices[i + 2]]) ) { gbm.DrawPolygon(pen, new System.Drawing.PointF[] { meshpoints[_TriangleIndices[i]], meshpoints[_TriangleIndices[i + 1]], meshpoints[_TriangleIndices[i + 2]] } ); } } } gbm.Dispose(); Image1.Source = CCommon.Bitmap2BitmapImage(bm); bm.Dispose(); bm = null; }