/* * corner-always-threshold <angle-in-degrees>: if the angle at a pixel is less than this, it is considered a corner, even if it is within `corner-surround' pixels of another corner; default is 60. * corner-surround <unsigned>: number of pixels on either side of a point to consider when determining if that point is a corner; default is 4. * corner-threshold <angle-in-degrees>: if a pixel, its predecessor(s), and its successor(s) meet at an angle smaller than this, it's a corner; default is 100. * despeckle-level <unsigned>: 0..20; default is no despeckling. * despeckle-tightness <real>: 0.0..8.0; default is 2.0. * imageerror-threshold <real>: subdivide fitted curves that are off by more pixels than this; default is 2.0. * filter-iterations <unsigned>: smooth the curve this many times before fitting; default is 4. * line-reversion-threshold <real>: if a spline is closer to a straight line than this, weighted by the square of the curve length, keep it a straight line even if it is a list with curves; default is .01. * line-threshold <real>: if the spline is not more than this far away from the straight line defined by its endpoints, then output a straight line; default is 1. * preserve-width: whether to preserve line width prior to thinning. * remove-adjacent-corners: remove corners that are adjacent. * tangent-surround <unsigned>: number of points on either side of a point to consider when computing the tangent at that point; default is 3. */ //System.Text.RegularExpressions.Regex colorRegex = new System.Text.RegularExpressions.Regex("stroke:#([0-9a-fA-F]+);", System.Text.RegularExpressions.RegexOptions.Compiled); private void PreviewCenterline(Bitmap bmp) { try { if (MustExitTH) { return; } Svg.SvgDocument svg = Autotrace.BitmapToSvgDocument(bmp, UseCornerThreshold, CornerThreshold, UseLineThreshold, LineThreshold); if (MustExitTH) { return; } using (Graphics g = Graphics.FromImage(bmp)) { g.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.White)), g.ClipBounds); if (MustExitTH) { return; } GraphicsPath path = new GraphicsPath(); svg.Draw(path); g.SmoothingMode = SmoothingMode.HighQuality; g.DrawPath(Pens.Red, path); } } catch (Exception ex) { using (Graphics g = Graphics.FromImage(bmp)) { if (MustExitTH) { return; } g.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.White)), g.ClipBounds); if (MustExitTH) { return; } StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; g.DrawString(ex.Message, SystemFonts.DefaultFont, Brushes.Red, new RectangleF(0, 0, bmp.Width, bmp.Height), format); if (MustExitTH) { return; } } } }
/* * corner-always-threshold <angle-in-degrees>: if the angle at a pixel is less than this, it is considered a corner, even if it is within `corner-surround' pixels of another corner; default is 60. * corner-surround <unsigned>: number of pixels on either side of a point to consider when determining if that point is a corner; default is 4. * corner-threshold <angle-in-degrees>: if a pixel, its predecessor(s), and its successor(s) meet at an angle smaller than this, it's a corner; default is 100. * despeckle-level <unsigned>: 0..20; default is no despeckling. * despeckle-tightness <real>: 0.0..8.0; default is 2.0. * imageerror-threshold <real>: subdivide fitted curves that are off by more pixels than this; default is 2.0. * filter-iterations <unsigned>: smooth the curve this many times before fitting; default is 4. * line-reversion-threshold <real>: if a spline is closer to a straight line than this, weighted by the square of the curve length, keep it a straight line even if it is a list with curves; default is .01. * line-threshold <real>: if the spline is not more than this far away from the straight line defined by its endpoints, then output a straight line; default is 1. * preserve-width: whether to preserve line width prior to thinning. * remove-adjacent-corners: remove corners that are adjacent. * tangent-surround <unsigned>: number of points on either side of a point to consider when computing the tangent at that point; default is 3. */ //System.Text.RegularExpressions.Regex colorRegex = new System.Text.RegularExpressions.Regex("stroke:#([0-9a-fA-F]+);", System.Text.RegularExpressions.RegexOptions.Compiled); private void PreviewCenterline(Bitmap bmp) { Svg.SvgDocument svg = Autotrace.BitmapToSvgDocument(bmp, UseCornerThreshold, CornerThreshold, UseLineThreshold, LineThreshold); if (MustExitTH) { return; } using (Graphics g = Graphics.FromImage(bmp)) { g.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.White)), g.ClipBounds); if (MustExitTH) { return; } GraphicsPath path = new GraphicsPath(); svg.Draw(path); g.SmoothingMode = SmoothingMode.HighQuality; g.DrawPath(Pens.Red, path); } }