/// <summary> /// Exports a figure, which was created by Potrace to a Bitmap. /// </summary> /// <param name="Fig">Arraylist, which contains vectorinformations about the Curves</param> /// <param name="Width">Width of the Bitmap</param> /// <param name="Height">Height of the Bitmap</param> /// <returns></returns> public static Bitmap Export2GDIPlus(ArrayList Fig, int Width, int Height) { Image I = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(I); g.FillRectangle(new SolidBrush(Color.White), 0, 0, Width, Height); GraphicsPath gp = new GraphicsPath(); for (int i = 0; i < Fig.Count; i++) { ArrayList CurveArray = (ArrayList)Fig[i]; GraphicsPath Contour = null; GraphicsPath Hole = null; GraphicsPath Current = null; for (int j = 0; j < CurveArray.Count; j++) { if (j == 0) { Contour = new GraphicsPath(); Current = Contour; } else { Hole = new GraphicsPath(); Current = Hole; } Potrace.Curve[] Curves = (Potrace.Curve[])CurveArray[j]; float factor = 1; for (int k = 0; k < Curves.Length; k++) { if (Curves[k].Kind == Potrace.CurveKind.Bezier) { Current.AddBezier((float)Curves[k].A.x * factor, (float)Curves[k].A.y * factor, (float)Curves[k].ControlPointA.x * factor, (float)Curves[k].ControlPointA.y * factor, (float)Curves[k].ControlPointB.x * factor, (float)Curves[k].ControlPointB.y * factor, (float)Curves[k].B.x * factor, (float)Curves[k].B.y * factor); } else { Current.AddLine((float)Curves[k].A.x * factor, (float)Curves[k].A.y * factor, (float)Curves[k].B.x * factor, (float)Curves[k].B.y * factor); } } if (j > 0) { Contour.AddPath(Hole, false); } } gp.AddPath(Contour, false); } g.FillPath(Brushes.Black, gp); return((Bitmap)I); }
/// <summary> /// potrace draw /// </summary> private void draw() { if (ListOfCurveArray == null) { return; } Graphics g = Graphics.FromImage(pictureBox1.Image); GraphicsPath gp = new GraphicsPath(); for (int i = 0; i < ListOfCurveArray.Count; i++) { ArrayList CurveArray = (ArrayList)ListOfCurveArray[i]; GraphicsPath Contour = null; GraphicsPath Hole = null; GraphicsPath Current = null; for (int j = 0; j < CurveArray.Count; j++) { if (j == 0) { Contour = new GraphicsPath(); Current = Contour; } else { Hole = new GraphicsPath(); Current = Hole; } Potrace.Curve[] Curves = (Potrace.Curve[])CurveArray[j]; float factor = 1; if (checkBox2.Checked) { factor = (trackBar1.Value + 1); } for (int k = 0; k < Curves.Length; k++) { if (Curves[k].Kind == Potrace.CurveKind.Bezier) { Current.AddBezier((float)Curves[k].A.x * factor, (float)Curves[k].A.y * factor, (float)Curves[k].ControlPointA.x * factor, (float)Curves[k].ControlPointA.y * factor, (float)Curves[k].ControlPointB.x * factor, (float)Curves[k].ControlPointB.y * factor, (float)Curves[k].B.x * factor, (float)Curves[k].B.y * factor); } else { Current.AddLine((float)Curves[k].A.x * factor, (float)Curves[k].A.y * factor, (float)Curves[k].B.x * factor, (float)Curves[k].B.y * factor); } } if (j > 0) { Contour.AddPath(Hole, false); } } gp.AddPath(Contour, false); } if (checkBox1.Checked) { g.DrawPath(Pens.Red, gp); } if (checkBox2.Checked) { showPoints(); } }
/// <summary> /// Zeichnet das erzeugte Vektorbild auf dem PictureBox /// </summary> void Draw() { if (ListOfCurveArray == null) { return; } Bitmap neuImage = new Bitmap(this.tableLayoutPanel1.Width / 2, this.tableLayoutPanel1.Height / 2); vectorizedImage_pictBox.Image = neuImage; Graphics neueZeichnung = Graphics.FromImage(neuImage); GraphicsPath neuerPfad = new GraphicsPath(); for (int i = 0; i < ListOfCurveArray.Count; i++) { ArrayList CurveArray = (ArrayList)ListOfCurveArray[i]; GraphicsPath Contour = null; GraphicsPath Hole = null; GraphicsPath Current = null; for (int j = 0; j < CurveArray.Count; j++) { if (j == 0) { Contour = new GraphicsPath(); Current = Contour; } else { Hole = new GraphicsPath(); Current = Hole; } Potrace.Curve[] Curves = (Potrace.Curve[])CurveArray[j]; for (int k = 0; k < Curves.Length; k++) { if (Curves[k].Kind == Potrace.CurveKind.Bezier) { Current.AddBezier((float)Curves[k].A.X, (float)Curves[k].A.Y, (float)Curves[k].ControlPointA.X, (float)Curves[k].ControlPointA.Y, (float)Curves[k].ControlPointB.X, (float)Curves[k].ControlPointB.Y, (float)Curves[k].B.X, (float)Curves[k].B.Y); } else { Current.AddLine((float)Curves[k].A.X, (float)Curves[k].A.Y, (float)Curves[k].B.X, (float)Curves[k].B.Y); } } if (j > 0) { Contour.AddPath(Hole, false); } neuerPfad.AddPath(Contour, false); } } if (befuellen_CheckBox.Checked) { neueZeichnung.FillPath(Brushes.DarkCyan, neuerPfad); } if (tracing_checkBox.Checked) { neueZeichnung.DrawPath(Pens.Black, neuerPfad); } if (punkte_anzeigen_checkbox.Checked) { Punkte_anzeigen(); } }