本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.AddBezier方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.AddBezier方法的具体用法?C# GraphicsPath.AddBezier怎么用?C# GraphicsPath.AddBezier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了GraphicsPath.AddBezier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RoundRect
public static GraphicsPath RoundRect(RectangleF r, float r1, float r2, float r3, float r4)
{
float x = r.X, y = r.Y, w = r.Width, h = r.Height;
GraphicsPath rr = new GraphicsPath();
rr.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y);
rr.AddLine(x + r1, y, x + w - r2, y);
rr.AddBezier(x + w - r2, y, x + w, y, x + w, y + r2, x + w, y + r2);
rr.AddLine(x + w, y + r2, x + w, y + h - r3);
rr.AddBezier(x + w, y + h - r3, x + w, y + h, x + w - r3, y + h, x + w - r3, y + h);
rr.AddLine(x + w - r3, y + h, x + r4, y + h);
rr.AddBezier(x + r4, y + h, x, y + h, x, y + h - r4, x, y + h - r4);
rr.AddLine(x, y + h - r4, x, y + r1);
return rr;
}
示例2: CreateRoundRect
public static GraphicsPath CreateRoundRect(RectangleF r, float r1, float r2, float r3, float r4)
{
float x = r.X;
float y = r.Y;
float width = r.Width;
float height = r.Height;
GraphicsPath path = new 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: RoundRect
public static GraphicsPath RoundRect(Rectangle rect, float r1, float r2, float r3, float r4)
{
int x = rect.X;
int y = rect.Y;
int width = rect.Width;
int height = rect.Height;
GraphicsPath path = new GraphicsPath();
path.AddBezier((float) x, y + r1, (float) x, (float) y, x + r1, (float) y, x + r1, (float) y);
path.AddLine(x + r1, (float) y, (x + width) - r2, (float) y);
path.AddBezier((x + width) - r2, (float) y, (float) (x + width), (float) y, (float) (x + width), y + r2, (float) (x + width), y + r2);
path.AddLine((float) (x + width), y + r2, (float) (x + width), (y + height) - r3);
path.AddBezier((float) (x + width), (y + height) - r3, (float) (x + width), (float) (y + height), (x + width) - r3, (float) (y + height), (x + width) - r3, (float) (y + height));
path.AddLine((x + width) - r3, (float) (y + height), x + r4, (float) (y + height));
path.AddBezier(x + r4, (float) (y + height), (float) x, (float) (y + height), (float) x, (y + height) - r4, (float) x, (y + height) - r4);
path.AddLine((float) x, (y + height) - r4, (float) x, y + r1);
return path;
}
示例4: ReturnBounds
public override RectangleF ReturnBounds()
{
GraphicsPath path = new GraphicsPath();
path.AddBezier(pointOne, pointTwo, pointTree, pointFour);
path.Transform(this.TMatrix.TransformationMatrix);
return path.GetBounds();
}
示例5: GetBarShape
/// <summary>
/// делает скругленные углы прямоугольнику rect с радиусом скругления cornerRad
/// </summary>
/// <param name="rect"></param> прямоугольник
/// <param name="cornerRad"></param> радиус скругления
/// <returns></returns>
public static GraphicsPath GetBarShape(RectangleF rect, float cornerRad)
{
float rad = cornerRad;
float x = rect.X;
float y = rect.Y;
float width = rect.Width;
float height = rect.Height;
GraphicsPath path = new GraphicsPath();
path.AddBezier(x, y + rad, x, y, x + rad, y, x + rad, y);
path.AddLine(x + rad, y, (x + width) - rad, y);
path.AddBezier((x + width) - rad, y, x + width, y, x + width, y + rad, x + width, y + rad);
path.AddLine((x + width), (y + rad), (x + width), ((y + height) - rad));
path.AddBezier((x + width), ((y + height) - rad), (x + width), (y + height), ((x + width) - rad), (y + height), ((x + width) - rad), (y + height));
path.AddLine(((x + width) - rad), (y + height), (x + rad), (y + height));
path.AddBezier(x + rad, y + height, x, y + height, x, (y + height) - rad, x, (y + height) - rad);
path.AddLine(x, (y + height) - rad, x, y + rad);
return path;
}
示例6: Rectangle
/// <summary>
/// Bygger og returnerer en et rektangel, med eventuelle avrundede hjørner
/// </summary>
/// <param name="x">Startpunktets x-koordinat</param>
/// <param name="y">Startpunktet y-koordinat</param>
/// <param name="width">Bredden på rektangelet</param>
/// <param name="height">Høyden på rektangelet</param>
/// <param name="leftTopRadius">Avrundingsverdi for hjørne oppe til venstre</param>
/// <param name="rightTopRadius">Avrundingsverdi for hjørne oppe til høyre</param>
/// <param name="rightBottomRadius">Avrundingsverdi for hjørne nede til høyre</param>
/// <param name="leftBottomRadius">Avrundingsverdi for hjørne nede til venstre</param>
/// <returns>Et GraphicsPath-objekt som representerer rektangelet</returns>
public static GraphicsPath Rectangle(int x, int y, int width, int height, int leftTopRadius, int rightTopRadius, int rightBottomRadius, int leftBottomRadius)
{
GraphicsPath p = new GraphicsPath();
//Punkter for øvre venstre hjørne
Point leftTopStart = new Point(x, y + leftTopRadius);
Point leftTopStop = new Point(x + leftTopRadius, y);
Point topLeftControlPoint = new Point(x, y);
//Punkter for øvre høyre hjørne
Point rightTopStart = new Point(x + width- rightTopRadius, y);
Point rightTopStop = new Point(x + width, y + rightTopRadius);
Point topRightControlPoint = new Point(x + width, y);
//Punkter for nedre høyre hjørne
Point rightBottomStart = new Point(x + width, y + height - rightBottomRadius);
Point rightBottomStop = new Point(x + width - rightBottomRadius, y + height);
Point bottomRightControlPoint = new Point(x + width, y + height);
//Punkter for nedre venstre hjørne
Point leftBottomStart = new Point(x + leftBottomRadius, y + height);
Point leftBottomStop = new Point(x, y + height - leftBottomRadius);
Point bottomLeftControlPoint = new Point(x, y + height);
p.StartFigure();
p.AddBezier(leftTopStart, topLeftControlPoint, topLeftControlPoint, leftTopStop); //Top left corner
p.AddLine(x + leftTopRadius, y, x + width - rightTopRadius, y); //Top edge
p.AddBezier(rightTopStart, topRightControlPoint, topRightControlPoint, rightTopStop); //Top right corner
p.AddLine(x + width, y + rightTopRadius, x + width, y + height - rightBottomRadius); //Right edge
p.AddBezier(rightBottomStart, bottomRightControlPoint, bottomRightControlPoint, rightBottomStop); // Bottom right corner
p.AddLine(x + width - rightBottomRadius, y + height, x + leftBottomRadius, y + height); //Bottom edge
p.AddBezier(leftBottomStart, bottomLeftControlPoint, bottomLeftControlPoint, leftBottomStop); // Bottom right corner
p.CloseFigure();
return p;
}
示例7: NextSubpath_Int_Int_Bool
public virtual void NextSubpath_Int_Int_Bool()
{
GraphicsPath path = new GraphicsPath ();
path.AddLine (new Point (100, 100), new Point (400, 100));
path.AddLine (new Point (400, 200), new Point (10, 100));
path.StartFigure ();
path.SetMarkers ();
path.AddBezier( 10, 10, 50, 250, 100, 5, 200, 280);
path.CloseFigure ();
path.StartFigure ();
path.SetMarkers ();
path.AddRectangle (new Rectangle (10, 20, 300, 400));
path.StartFigure ();
path.SetMarkers ();
path.AddLine (new Point (400, 400), new Point (400, 10));
GraphicsPathIterator iterator = new GraphicsPathIterator (path);
int start;
int end;
bool isClosed;
int count = iterator.NextSubpath (out start, out end, out isClosed);
Assert.AreEqual (4, count);
Assert.AreEqual (0, start);
Assert.AreEqual (3, end);
Assert.IsFalse (isClosed);
count = iterator.NextSubpath (out start, out end, out isClosed);
Assert.AreEqual (4, count);
Assert.AreEqual (4, start);
Assert.AreEqual (7, end);
Assert.IsTrue (isClosed);
count = iterator.NextSubpath (out start, out end, out isClosed);
Assert.AreEqual (4, count);
Assert.AreEqual (8, start);
Assert.AreEqual (11, end);
Assert.IsTrue (isClosed);
count = iterator.NextSubpath (out start, out end, out isClosed);
Assert.AreEqual (2, count);
Assert.AreEqual (12, start);
Assert.AreEqual (13, end);
Assert.IsFalse (isClosed);
count = iterator.NextSubpath (out start, out end, out isClosed);
Assert.AreEqual (0, count);
Assert.AreEqual (0, start);
Assert.AreEqual (0, end);
Assert.IsTrue (isClosed);
}
示例8: DrawYourSelf
public override void DrawYourSelf(Graphics graphics)
{
GraphicsPath path = new GraphicsPath();
path.AddBezier(pointOne, pointTwo, pointTree, pointFour);
path.Transform(this.TMatrix.TransformationMatrix);
Pen pen = new Pen(this.BorderColor, this.BorderWidth);
graphics.DrawPath(pen, path);
if (this.Selected)
{
this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
this.selectionUnit.DrawYourSelf(graphics);
}
}
示例9: AnimateFrame
private void AnimateFrame(Rectangle box, Graphics g, ref int marqueeX) {
if (box == null || g == null || box.Width <= 1) { return; }
g.SmoothingMode = SmoothingMode.AntiAlias;
//g.Clip = new Region(box);
g.FillRectangle(new SolidBrush(color1), box);
int h = box.Height;
int hm = (int)((float)h / 2f);
using (GraphicsPath gp = new GraphicsPath()) {
Point MidLeft = new Point(0, hm);
Point MidRight = new Point(h * 2, hm);
int currentX = box.Right + animateX; // Increment currentX to animate
int left = currentX - (h * 2);
if (left < box.Left) { left = box.Left; }
while (currentX > box.Left) {
left = currentX - (h * 2);
MidLeft = new Point(left, hm);
MidRight = new Point(currentX, hm);
int crestX = currentX - h;
gp.AddBezier(MidRight, new Point(crestX, 0), new Point(crestX, h), MidLeft);
currentX -= h * 2;
}
gp.AddLine(MidLeft, new Point(box.Left, box.Bottom)); // left side
gp.AddLine(new Point(box.Left, box.Bottom), new Point(box.Right, box.Bottom)); // bottom
gp.AddLine(new Point(box.Right, box.Bottom), new Point(box.Right, hm)); // right side
g.FillPath(new SolidBrush(color2), gp);
}
g.SmoothingMode = SmoothingMode.Default;
if (isAnimated && ++animateX > (box.Height * 2)) {
animateX = 1;
}
}
示例10: CreateGraphicsPath
internal static GraphicsPath CreateGraphicsPath(ICurve iCurve) {
GraphicsPath graphicsPath = new GraphicsPath();
if (iCurve == null)
return null;
Curve c = iCurve as Curve;
if (c != null)
{
foreach (ICurve seg in c.Segments)
{
CubicBezierSegment cubic = seg as CubicBezierSegment;
if (cubic != null)
graphicsPath.AddBezier(PointF(cubic.B(0)), PointF(cubic.B(1)), PointF(cubic.B(2)), PointF(cubic.B(3)));
else
{
LineSegment ls = seg as LineSegment;
if (ls != null)
graphicsPath.AddLine(PointF(ls.Start), PointF(ls.End));
else
{
Ellipse el = seg as Ellipse;
if (el != null)
{
graphicsPath.AddArc((float)(el.Center.X - el.AxisA.X), (float)(el.Center.Y - el.AxisB.Y), (float)(el.AxisA.X * 2), Math.Abs((float)el.AxisB.Y * 2), EllipseStartAngle(el), EllipseSweepAngle(el));
}
}
}
}
}
else {
var ls = iCurve as LineSegment;
if (ls != null)
graphicsPath.AddLine(PointF(ls.Start), PointF(ls.End));
}
return graphicsPath;
}
示例11: Deshret
public static GraphicsPath Deshret()
{
GraphicsPath gp = new GraphicsPath();
PointF[] tempA = deshretData[0x00];
PointF p1, p2, p3, p4 = tempA[0x00];
int j = 0x01;
for(int i = 0x00; i < 0x0b; i++) {
p1 = p4;
p2 = tempA[j++];
p3 = tempA[j++];
p4 = tempA[j++];
gp.AddBezier(p1,p2,p3,p4);
}
p1 = p4;
p4 = tempA[j++];
gp.AddLine(p1,p4);
for(int i = 0x00; i < 0x07; i++) {
p1 = p4;
p2 = tempA[j++];
p3 = tempA[j++];
p4 = tempA[j++];
gp.AddBezier(p1,p2,p3,p4);
}
gp.CloseFigure();
tempA = deshretData[0x01];
p4 = tempA[0x00];
j = 0x01;
for(int i = 0x00; i < 0x14; i++) {
p1 = p4;
p2 = tempA[j++];
p3 = tempA[j++];
p4 = tempA[j++];
gp.AddBezier(p1,p2,p3,p4);
}
gp.AddLine(p4,tempA[j++]);
gp.CloseFigure();
return gp;
}
示例12: Reverse_Subpath_Marker_2
public void Reverse_Subpath_Marker_2 ()
{
using (GraphicsPath gp = new GraphicsPath ()) {
gp.AddLine (0, 1, 2, 3);
gp.SetMarkers ();
gp.StartFigure ();
gp.AddLine (20, 21, 22, 23);
gp.AddBezier (5, 6, 7, 8, 9, 10, 11, 12);
PointF[] bp = gp.PathPoints;
byte[] expected = new byte[] { 0, 3, 3, 3, 1, 33, 0, 1 };
gp.Reverse ();
PointF[] ap = gp.PathPoints;
byte[] at = gp.PathTypes;
int count = gp.PointCount;
Assert.AreEqual (bp.Length, count, "PointCount");
for (int i = 0; i < count; i++) {
Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ());
}
}
}
示例13: BuildMenuIconShape
private GraphicsPath BuildMenuIconShape( ref Rectangle rcMenuIcon)
{
GraphicsPath XMenuIconPath = new GraphicsPath();
switch (m_xTitleBar.TitleBarType)
{
case XTitleBar.XTitleBarType.Rounded:
XMenuIconPath.AddArc(
rcMenuIcon.Left,
rcMenuIcon.Top,
rcMenuIcon.Height,
rcMenuIcon.Height,
90,
180);
XMenuIconPath.AddLine(
rcMenuIcon.Left + rcMenuIcon.Height / 2,
rcMenuIcon.Top,
rcMenuIcon.Right,
rcMenuIcon.Top
);
XMenuIconPath.AddBezier(
new Point(rcMenuIcon.Right, rcMenuIcon.Top),
new Point(rcMenuIcon.Right - 10, rcMenuIcon.Bottom / 2 - 5),
new Point(rcMenuIcon.Right - 12, rcMenuIcon.Bottom / 2 + 5),
new Point(rcMenuIcon.Right, rcMenuIcon.Bottom)
);
XMenuIconPath.AddLine(
rcMenuIcon.Right,
rcMenuIcon.Bottom,
rcMenuIcon.Left + rcMenuIcon.Height / 2,
rcMenuIcon.Bottom
);
break;
case XTitleBar.XTitleBarType.Angular:
XMenuIconPath.AddArc(
rcMenuIcon.Left,
rcMenuIcon.Top,
rcMenuIcon.Height,
rcMenuIcon.Height,
90,
180);
XMenuIconPath.AddLine(
rcMenuIcon.Left + rcMenuIcon.Height / 2,
rcMenuIcon.Top,
rcMenuIcon.Right + 18,
rcMenuIcon.Top
);
XMenuIconPath.AddLine(
rcMenuIcon.Right + 18,
rcMenuIcon.Top,
rcMenuIcon.Right - 5,
rcMenuIcon.Bottom
);
XMenuIconPath.AddLine(
rcMenuIcon.Right - 5,
rcMenuIcon.Bottom,
rcMenuIcon.Left + rcMenuIcon.Height / 2,
rcMenuIcon.Bottom
);
break;
case XTitleBar.XTitleBarType.Rectangular:
XMenuIconPath.AddArc(
rcMenuIcon.Left,
rcMenuIcon.Top,
rcMenuIcon.Height,
rcMenuIcon.Height,
90,
180);
XMenuIconPath.AddLine(
rcMenuIcon.Left + rcMenuIcon.Height / 2,
rcMenuIcon.Top,
rcMenuIcon.Right,
rcMenuIcon.Top
);
XMenuIconPath.AddLine(
rcMenuIcon.Right,
rcMenuIcon.Top,
rcMenuIcon.Right,
rcMenuIcon.Bottom
);
XMenuIconPath.AddLine(
rcMenuIcon.Right,
rcMenuIcon.Bottom,
rcMenuIcon.Left + rcMenuIcon.Height / 2,
rcMenuIcon.Bottom
);
break;
}
return XMenuIconPath;
}
示例14: AddToPath
public override void AddToPath(GraphicsPath graphicsPath)
{
if (this.Start == this.End)
{
return;
}
if (this.RadiusX == 0.0f && this.RadiusY == 0.0f)
{
graphicsPath.AddLine(this.Start, this.End);
return;
}
double sinPhi = Math.Sin(this.Angle * SvgArcSegment.RadiansPerDegree);
double cosPhi = Math.Cos(this.Angle * SvgArcSegment.RadiansPerDegree);
double x1dash = cosPhi * (this.Start.X - this.End.X) / 2.0 + sinPhi * (this.Start.Y - this.End.Y) / 2.0;
double y1dash = -sinPhi * (this.Start.X - this.End.X) / 2.0 + cosPhi * (this.Start.Y - this.End.Y) / 2.0;
double root;
double numerator = this.RadiusX * this.RadiusX * this.RadiusY * this.RadiusY - this.RadiusX * this.RadiusX * y1dash * y1dash - this.RadiusY * this.RadiusY * x1dash * x1dash;
float rx = this.RadiusX;
float ry = this.RadiusY;
if (numerator < 0.0)
{
float s = (float)Math.Sqrt(1.0 - numerator / (this.RadiusX * this.RadiusX * this.RadiusY * this.RadiusY));
rx *= s;
ry *= s;
root = 0.0;
}
else
{
root = ((this.Size == SvgArcSize.Large && this.Sweep == SvgArcSweep.Positive) || (this.Size == SvgArcSize.Small && this.Sweep == SvgArcSweep.Negative) ? -1.0 : 1.0) * Math.Sqrt(numerator / (this.RadiusX * this.RadiusX * y1dash * y1dash + this.RadiusY * this.RadiusY * x1dash * x1dash));
}
double cxdash = root * rx * y1dash / ry;
double cydash = -root * ry * x1dash / rx;
double cx = cosPhi * cxdash - sinPhi * cydash + (this.Start.X + this.End.X) / 2.0;
double cy = sinPhi * cxdash + cosPhi * cydash + (this.Start.Y + this.End.Y) / 2.0;
double theta1 = SvgArcSegment.CalculateVectorAngle(1.0, 0.0, (x1dash - cxdash) / rx, (y1dash - cydash) / ry);
double dtheta = SvgArcSegment.CalculateVectorAngle((x1dash - cxdash) / rx, (y1dash - cydash) / ry, (-x1dash - cxdash) / rx, (-y1dash - cydash) / ry);
if (this.Sweep == SvgArcSweep.Negative && dtheta > 0)
{
dtheta -= 2.0 * Math.PI;
}
else if (this.Sweep == SvgArcSweep.Positive && dtheta < 0)
{
dtheta += 2.0 * Math.PI;
}
int segments = (int)Math.Ceiling((double)Math.Abs(dtheta / (Math.PI / 2.0)));
double delta = dtheta / segments;
double t = 8.0 / 3.0 * Math.Sin(delta / 4.0) * Math.Sin(delta / 4.0) / Math.Sin(delta / 2.0);
double startX = this.Start.X;
double startY = this.Start.Y;
for (int i = 0; i < segments; ++i)
{
double cosTheta1 = Math.Cos(theta1);
double sinTheta1 = Math.Sin(theta1);
double theta2 = theta1 + delta;
double cosTheta2 = Math.Cos(theta2);
double sinTheta2 = Math.Sin(theta2);
double endpointX = cosPhi * rx * cosTheta2 - sinPhi * ry * sinTheta2 + cx;
double endpointY = sinPhi * rx * cosTheta2 + cosPhi * ry * sinTheta2 + cy;
double dx1 = t * (-cosPhi * rx * sinTheta1 - sinPhi * ry * cosTheta1);
double dy1 = t * (-sinPhi * rx * sinTheta1 + cosPhi * ry * cosTheta1);
double dxe = t * (cosPhi * rx * sinTheta2 + sinPhi * ry * cosTheta2);
double dye = t * (sinPhi * rx * sinTheta2 - cosPhi * ry * cosTheta2);
graphicsPath.AddBezier((float)startX, (float)startY, (float)(startX + dx1), (float)(startY + dy1),
(float)(endpointX + dxe), (float)(endpointY + dye), (float)endpointX, (float)endpointY);
theta1 = theta2;
startX = (float)endpointX;
startY = (float)endpointY;
}
}
示例15: SyntaxToPath
public GraphicsPath SyntaxToPath(string PathSyntax)
{
List<string> t = Tokenize(PathSyntax);
if (t.Count < 2) return new GraphicsPath();
GraphicsPath p = new GraphicsPath();
int i = 0;
if (t[0] == "F1") {
p.FillMode = FillMode.Winding;
i++;
} else if (t[0] == "F0") {
p.FillMode = FillMode.Alternate;
i++;
}
PointF last_point = new PointF(0, 0);
for (; i < t.Count; i++) {
switch (t[i]) { // doesn't handle a lot of short-cuts yet. Doesn't support Hh or Vv
case "M":
p.StartFigure();
last_point = GetPointStr(t[i + 1], t[i + 2]);
i += 2;
break;
case "m":
p.StartFigure();
last_point = GetPointStrOff(t[i + 1], t[i + 2], last_point);
i += 2;
break;
case "L":
p.AddLine(last_point, GetPointStr(t[i + 1], t[i + 2]));
last_point = p.GetLastPoint();
i += 2;
break;
case "l":
p.AddLine(last_point, GetPointStrOff(t[i + 1], t[i + 2], last_point));
last_point = p.GetLastPoint();
i += 2;
break;
case "C":
p.AddBezier(last_point, GetPointStr(t[i + 1], t[i + 2]), GetPointStr(t[i + 3], t[i + 4]), GetPointStr(t[i + 5], t[i + 6]));
last_point = p.GetLastPoint();
i += 6;
break;
case "Z":
case "z":
p.CloseFigure();
break;
default:
throw new Exception("Unsupported symbol: " + t[i]);
}
}
p.CloseAllFigures();
return p;
}