/// <summary> /// Vectorize /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { ListOfCurveArray = new ArrayList(); Potrace.turdsize = Convert.ToInt32(textBox1.Text); try { Potrace.alphamax = Convert.ToDouble(textBox3.Text); } catch { textBox3.Text = Potrace.alphamax.ToString(); } try { Potrace.opttolerance = Convert.ToDouble(textBox2.Text); } catch { textBox2.Text = Potrace.opttolerance.ToString(); } //optimize the path p, replacing sequences of Bezier segments by a //single segment when possible. Potrace.curveoptimizing = true; //checkBox3.Checked; Matrix = Potrace.BitMapToBinary(Bitmap, trackBar2.Value); Potrace.potrace_trace(Matrix, ListOfCurveArray); refreshMatrix(); }
private List <Models.Game.Path> ConvertBitmapToStrokes(Bitmap bitmap) { bool[,] Matrix; ArrayList ListOfCurveArray; ListOfCurveArray = new ArrayList(); Matrix = Potrace.BitMapToBinary(bitmap, 150); Potrace.potrace_trace(Matrix, ListOfCurveArray); string selectedColor = "Black"; int lineSize = 11; string shape = "rond"; var listOfStrokes = new List <Models.Game.Path>(); var canvasId = Guid.NewGuid().ToString(); for (int i = 0; i < ListOfCurveArray.Count; i++) { ArrayList CurveArray = (ArrayList)ListOfCurveArray[i]; for (int j = 0; j < CurveArray.Count; j++) { Potrace.Curve[] Curves = (Potrace.Curve[])CurveArray[j]; var stroke = new Models.Game.Path(Guid.NewGuid().ToString(), canvasId, lineSize, selectedColor, false, shape); for (int k = 0; k < Curves.Length; k++) { if (Curves[k].Kind == Potrace.CurveKind.Bezier) { stroke.Coordinates.Add(new Coordinate() { X = Curves[k].A.X, Y = Curves[k].A.Y }); stroke.Coordinates.Add(new Coordinate() { X = Curves[k].ControlPointA.X, Y = Curves[k].ControlPointA.Y }); stroke.Coordinates.Add(new Coordinate() { X = Curves[k].ControlPointB.X, Y = Curves[k].ControlPointB.Y }); stroke.Coordinates.Add(new Coordinate() { X = Curves[k].B.X, Y = Curves[k].B.Y }); } else { stroke.Coordinates.Add(new Coordinate() { X = Curves[k].A.X, Y = Curves[k].A.Y }); stroke.Coordinates.Add(new Coordinate() { X = Curves[k].B.X, Y = Curves[k].B.Y }); } } listOfStrokes.Add(stroke); } } return(listOfStrokes); }
private void vectorize() { ListOfCurveArray = new ArrayList(); Potrace.turdsize = Convert.ToInt32(contrastSlider.Value); Potrace.curveoptimizing = true; Matrix = Potrace.BitMapToBinary(Bitmap, (int)contrastSlider.Value); Potrace.potrace_trace(Matrix, ListOfCurveArray); Bitmap s = Potrace.Export2GDIPlus(ListOfCurveArray, Bitmap.Width, Bitmap.Height); imgPhoto.Source = BitmapToImageSource(s); refreshMatrix(); }
/// <summary> /// Vectorize the image /// </summary> void Vectorize() { Bitmap = new Bitmap(loaded_Image); ListOfCurveArray = new ArrayList(); Potrace.turdsize = ignore_area_pixel; Potrace.alphamax = AlphaMax; Potrace.opttolerance = curve_tolerance; Potrace.curveoptimizing = Curveoptimizing; Matrix = Potrace.BitMapToBinary(Bitmap, tresHold); Potrace.potrace_trace(Matrix, ListOfCurveArray); ListElement_Image = new List <List <object> >(); ListOfLine = new List <LineF>(); }