DrawBinarySplitPolyLine.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Annotation.Label;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Windows.Forms;
  7. namespace PaintDotNet.Annotation.Other
  8. {
  9. /// <summary>
  10. /// 二值提取 - 交互操作 - 分割 - 折线
  11. /// </summary>
  12. public class DrawBinarySplitPolyLine : DrawObject
  13. {
  14. public List<Point> pointArray = new List<Point>();
  15. public DrawBinarySplitPolyLine(ISurfaceBox surfaceBox, int x1, int y1) : base()
  16. {
  17. this.objectType = DrawClass.Interaction;
  18. this.drawToolType = DrawToolType.BinarySplitPolyline;
  19. this.ISurfaceBox = surfaceBox;
  20. startPoint.X = x1;
  21. startPoint.Y = y1;
  22. endPoint.X = x1;
  23. endPoint.Y = y1;
  24. pointArray.Add(new Point(x1, y1));
  25. Initialize();
  26. }
  27. public override DrawObject Clone()
  28. {
  29. return null;
  30. }
  31. public override void Draw(Graphics g)
  32. {
  33. if (HandleCount >= 2)
  34. {
  35. g.SmoothingMode = SmoothingMode.AntiAlias;
  36. Pen pen = new Pen(Color.Red, this.ISurfaceBox.GetSegmentationWidth());
  37. pen.DashStyle = DashStyle.Dash;
  38. g.DrawLines(pen, pointArray.ToArray());
  39. pen.Dispose();
  40. }
  41. }
  42. public void AddPoint(Point point)
  43. {
  44. pointArray.Add(point);
  45. }
  46. internal void setNextPoint(Point p)
  47. {
  48. AddPoint(p);
  49. startPoint = endPoint;
  50. endPoint = p;
  51. }
  52. public override RectangleF GetBoundingBox()
  53. {
  54. return rectangle;
  55. }
  56. public override void MoveHandleTo(Point point, int handleNumber)
  57. {
  58. if (handleNumber < 1)
  59. handleNumber = 1;
  60. if (handleNumber > pointArray.Count)
  61. handleNumber = pointArray.Count;
  62. pointArray[handleNumber - 1] = point;
  63. }
  64. public override int HandleCount
  65. {
  66. get
  67. {
  68. return pointArray.Count;
  69. }
  70. }
  71. }
  72. }