本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.AddBezier方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Drawing2D.GraphicsPath.AddBezier方法的具体用法?C# System.Drawing.Drawing2D.GraphicsPath.AddBezier怎么用?C# System.Drawing.Drawing2D.GraphicsPath.AddBezier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了System.Drawing.Drawing2D.GraphicsPath.AddBezier方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getDrawingPoints
/// <summary>
/// takes in a parsed path and returns a list of points that can be used to draw the path
/// </summary>
/// <returns>The drawing points.</returns>
/// <param name="segments">Segments.</param>
public Vector2[] getDrawingPoints( List<SvgPathSegment> segments, float flatness = 3 )
{
var path = new System.Drawing.Drawing2D.GraphicsPath();
for( var j = 0; j < segments.Count; j++ )
{
var segment = segments[j];
if( segment is SvgMoveToSegment )
{
path.StartFigure();
}
else if( segment is SvgCubicCurveSegment )
{
var cubicSegment = segment as SvgCubicCurveSegment;
path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( cubicSegment.firstCtrlPoint ), toDrawPoint( cubicSegment.secondCtrlPoint ), toDrawPoint( segment.end ) );
}
else if( segment is SvgClosePathSegment )
{
// important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
if( path.PointCount > 0 && !path.PathPoints[0].Equals( path.PathPoints[path.PathPoints.Length - 1] ) )
{
var i = path.PathTypes.Length - 1;
while( i >= 0 && path.PathTypes[i] > 0 )
i--;
if( i < 0 )
i = 0;
path.AddLine( path.PathPoints[path.PathPoints.Length - 1], path.PathPoints[i] );
}
path.CloseFigure();
}
else if( segment is SvgLineSegment )
{
path.AddLine( toDrawPoint( segment.start ), toDrawPoint( segment.end ) );
}
else if( segment is SvgQuadraticCurveSegment )
{
var quadSegment = segment as SvgQuadraticCurveSegment;
path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( quadSegment.firstCtrlPoint ), toDrawPoint( quadSegment.secondCtrlPoint ), toDrawPoint( segment.end ) );
}
else
{
Debug.warn( "unknown type in getDrawingPoints" );
}
}
path.Flatten( new System.Drawing.Drawing2D.Matrix(), flatness );
return System.Array.ConvertAll( path.PathPoints, i => new Vector2( i.X, i.Y ) );
}
示例2: DrawRoundRect
public static System.Drawing.Drawing2D.GraphicsPath DrawRoundRect(Rectangle r, int r1, int r2, int r3, int r4)
{
float x = r.X;
float y = r.Y;
float width = r.Width;
float height = r.Height;
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y);
path.AddLine(x + r1, y, (x + width) - r2, y);
path.AddBezier((x + width) - r2, y, x + width, y, x + width, y + r2, x + width, y + r2);
path.AddLine((float)(x + width), (float)(y + r2), (float)(x + width), (float)((y + height) - r3));
path.AddBezier((float)(x + width), (float)((y + height) - r3), (float)(x + width), (float)(y + height), (float)((x + width) - r3), (float)(y + height), (float)((x + width) - r3), (float)(y + height));
path.AddLine((float)((x + width) - r3), (float)(y + height), (float)(x + r4), (float)(y + height));
path.AddBezier(x + r4, y + height, x, y + height, x, (y + height) - r4, x, (y + height) - r4);
path.AddLine(x, (y + height) - r4, x, y + r1);
return path;
}
示例3: Fill
/// <summary>
/// Fill a closed path composed of several drawing operations
/// </summary>
/// <param name="canvas"></param>
public void Fill(System.Drawing.Graphics canvas)
{
System.Drawing.Drawing2D.GraphicsPath path;
path = new System.Drawing.Drawing2D.GraphicsPath();
for (int i = 0; i < m_drawings.Count; i++)
{
switch (m_drawings[i].Type)
{
case DrawingType.Line:
{
path.AddLine(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[1].x, m_drawings[i].Points[1].y);
break;
}
case DrawingType.Arc:
{
double startAngle, endAngle;
startAngle = System.Math.Atan2(m_drawings[i].Points[2].y - (m_drawings[i].Points[1].y + m_drawings[i].Points[0].y) / 2, m_drawings[i].Points[2].x - (m_drawings[i].Points[1].x + m_drawings[i].Points[0].x) / 2);
if (startAngle < 0)
{
startAngle += System.Math.PI * 2;
}
startAngle = (startAngle / Math.PI) * 180;
endAngle = System.Math.Atan2(m_drawings[i].Points[3].y - (m_drawings[i].Points[1].y + m_drawings[i].Points[0].y) / 2, m_drawings[i].Points[3].x - (m_drawings[i].Points[1].x + m_drawings[i].Points[0].x) / 2);
if (endAngle < 0)
{
endAngle += System.Math.PI * 2;
}
endAngle = (endAngle / Math.PI) * 180;
path.AddArc(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[1].x - m_drawings[i].Points[0].x, m_drawings[i].Points[1].y - m_drawings[i].Points[0].y, (float)startAngle, Math.Abs((float)(endAngle - startAngle)));
break;
}
case DrawingType.Bezier:
{
path.AddBezier(m_drawings[i].Points[0].x, m_drawings[i].Points[0].y, m_drawings[i].Points[2].x, m_drawings[i].Points[2].y, m_drawings[i].Points[3].x, m_drawings[i].Points[3].y, m_drawings[i].Points[1].x, m_drawings[i].Points[1].y);
break;
}
}
}
canvas.FillPath(m_style.fillingStyle, path);
}
示例4: ResolveGraphicsPath
static System.Drawing.Drawing2D.GraphicsPath ResolveGraphicsPath(GraphicsPath path)
{
//convert from graphics path to internal presentation
System.Drawing.Drawing2D.GraphicsPath innerPath = path.InnerPath as System.Drawing.Drawing2D.GraphicsPath;
if (innerPath != null)
{
return innerPath;
}
//--------
innerPath = new System.Drawing.Drawing2D.GraphicsPath();
path.InnerPath = innerPath;
List<float> points;
List<PathCommand> cmds;
GraphicsPath.GetPathData(path, out points, out cmds);
int j = cmds.Count;
int p_index = 0;
for (int i = 0; i < j; ++i)
{
PathCommand cmd = cmds[i];
switch (cmd)
{
default:
throw new NotSupportedException();
case PathCommand.Arc:
innerPath.AddArc(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3],
points[p_index + 4],
points[p_index + 5]);
p_index += 6;
break;
case PathCommand.Bezier:
innerPath.AddBezier(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3],
points[p_index + 4],
points[p_index + 5],
points[p_index + 6],
points[p_index + 7]);
p_index += 8;
break;
case PathCommand.CloseFigure:
innerPath.CloseFigure();
break;
case PathCommand.Ellipse:
innerPath.AddEllipse(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]);
p_index += 4;
break;
case PathCommand.Line:
innerPath.AddLine(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]);
p_index += 4;
break;
case PathCommand.Rect:
innerPath.AddRectangle(
new System.Drawing.RectangleF(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]));
p_index += 4;
break;
case PathCommand.StartFigure:
break;
}
}
return innerPath;
}