本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.Flatten方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.Flatten方法的具体用法?C# GraphicsPath.Flatten怎么用?C# GraphicsPath.Flatten使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了GraphicsPath.Flatten方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Analyzer
public Analyzer(double meanX, double meanY, GraphicsPath path)
{
Counters = new RunningCount[Enum.GetValues(typeof(AnalysisMetric)).Length];
foreach(AnalysisMetric metric in Enum.GetValues(typeof(AnalysisMetric)))
Counters[(int)metric] = new RunningCount(metric);
MeanX = meanX;
MeanY = meanY;
path.Flatten();
using(GraphicsPathIterator PathIterator = new GraphicsPathIterator(path))
{
using(GraphicsPath Subpath = new GraphicsPath())
{
Paths = new List<PointF[]>();
bool Closed;
while(PathIterator.NextSubpath(Subpath, out Closed) > 0)
{
Paths.Add(Subpath.PathPoints);
Subpath.Reset();
}
}
}
}
示例2: WarpPath
public static void WarpPath(GraphicsPath path, PointF[] destPoints, RectangleF srcRect, Matrix matrix = null, WarpMode warpMode = WarpMode.Perspective, float flatness = 0.25f)
{
if (path.PointCount == 0)
return;
path.Flatten(matrix, flatness);
var pathData = path.PathData;
var pnts = path.PathPoints;
var srcPoints = new PointF[] { new PointF(srcRect.Left, srcRect.Top),
new PointF(srcRect.Right, srcRect.Top),
new PointF(srcRect.Left, srcRect.Bottom),
new PointF(srcRect.Right, srcRect.Bottom) };
var count = pnts.Length;
float x1, y1;
int i;
if (warpMode == WarpMode.Perspective)
{
CalcProjectiveXformCoeffs(srcPoints, destPoints, out coeffs);
for (i = 0; i < count; i++)
{
x1 = pnts[i].X;
y1 = pnts[i].Y;
var factor = 1.0f / (coeffs[6] * x1 + coeffs[7] * y1 + 1.0f);
pnts[i].X = (float)(factor * (coeffs[0] * x1 + coeffs[1] * y1 + coeffs[2]));
pnts[i].Y = (float)(factor * (coeffs[3] * x1 + coeffs[4] * y1 + coeffs[5]));
}
}
else
{
CalcBilinearXformCoeffs(srcPoints, destPoints, out coeffs);
for (i = 0; i < count; i++)
{
x1 = pnts[i].X;
y1 = pnts[i].Y;
pnts[i].X = (float)(coeffs[0] * x1 + coeffs[1] * y1 + coeffs[2] * x1 * y1 + coeffs[3]);
pnts[i].Y = (float)(coeffs[4] * x1 + coeffs[5] * y1 + coeffs[6] * x1 * y1 + coeffs[7]);
}
}
GraphicsPath warpedPath = new GraphicsPath(pnts, pathData.Types);
if (warpedPath != null)
{
FillMode fm = path.FillMode;
path.Reset();
path.FillMode = fm;
path.AddPath(warpedPath, true);
warpedPath.Dispose();
}
}
示例3: GetEllipse
/// <summary>
/// Get the desired Rounded Rectangle path.
/// </summary>
private static GraphicsPath GetEllipse(RectangleF baseRect)
{
GraphicsPath mPath = new GraphicsPath();
mPath.AddEllipse(baseRect);
mPath.CloseFigure();
mPath.Flatten();
return mPath;
}
示例4: Form2_Paint
private void Form2_Paint(object sender, PaintEventArgs e)
{
//패스 그래디언트
Point[] pts = { new Point(100, 0), new Point(0, 100), new Point(200, 100) };
PathGradientBrush B = new PathGradientBrush(pts, WrapMode.Tile);
e.Graphics.FillRectangle(B, ClientRectangle);
//패스 그래디언트 끝
//패스변형
GraphicsPath Path = new GraphicsPath();
Path.AddString("한글", new FontFamily("궁서"), 0, 100, new Point(10, 30), new StringFormat());
//확장 후 외곽선 그리기
Path.Widen(new Pen(Color.Black, 3));
e.Graphics.DrawPath(Pens.Black, Path);
//확장 후 채우기
Path.Widen(new Pen(Color.Blue, 3));
e.Graphics.DrawPath(Pens.Black, Path);
//곡선 펴기
Path.Flatten(new Matrix(), 12f);
e.Graphics.DrawPath(Pens.Black, Path);
//회전
Matrix M = new Matrix();
M.Rotate(-10);
Path.Transform(M);
e.Graphics.FillPath(Brushes.Blue, Path);
//휘기
RectangleF R = Path.GetBounds();
PointF[] arPoint = new PointF[4];
arPoint[0] = new PointF(R.Left, R.Top + 30);
arPoint[1] = new PointF(R.Right, R.Top - 10);
arPoint[2] = new PointF(R.Left + 10, R.Bottom - 10);
arPoint[3] = new PointF(R.Right + 30, R.Bottom + 30);
Path.Warp(arPoint, R);
e.Graphics.FillPath(Brushes.Blue, Path);
//클리핑
//graphicspath path= new graphicspath();
//path.fillmode = fillmode.winding;
//path.addellipse(50, 10, 100, 80);
//path.addellipse(20, 45, 160, 120);
//e.graphics.fillpath(brushes.white, path);
//e.graphics.setclip(path);
//for (int y = 0; y < bottom; y+= 20)
//{
// string str = "눈사람의 모양의클리핑 영역에 글자를 쓴것입니다";
// e.graphics.drawstring(str, font, brushes.blue, 0, y);
//}
//클리핑 끝
}
示例5: DrawColorWheel
private static void DrawColorWheel(Graphics gr, Color outline_color, int xmin, int ymin, int wid, int hgt)
{
Rectangle rect = new Rectangle(xmin, ymin, wid, hgt);
GraphicsPath wheel_path = new GraphicsPath();
wheel_path.AddEllipse(rect);
wheel_path.Flatten();
float num_pts = (wheel_path.PointCount - 1) / 6;
Color[] surround_colors = new Color[wheel_path.PointCount];
int index = 0;
InterpolateColors(surround_colors, ref index,
1 * num_pts, 255, 255, 0, 0, 255, 255, 0, 255);
InterpolateColors(surround_colors, ref index,
2 * num_pts, 255, 255, 0, 255, 255, 0, 0, 255);
InterpolateColors(surround_colors, ref index,
3 * num_pts, 255, 0, 0, 255, 255, 0, 255, 255);
InterpolateColors(surround_colors, ref index,
4 * num_pts, 255, 0, 255, 255, 255, 0, 255, 0);
InterpolateColors(surround_colors, ref index,
5 * num_pts, 255, 0, 255, 0, 255, 255, 255, 0);
InterpolateColors(surround_colors, ref index,
wheel_path.PointCount, 255, 255, 255, 0, 255, 255, 0, 0);
using (PathGradientBrush path_brush =
new PathGradientBrush(wheel_path))
{
path_brush.CenterColor = Color.White;
path_brush.SurroundColors = surround_colors;
gr.FillPath(path_brush, wheel_path);
// It looks better if we outline the wheel.
using (Pen thick_pen = new Pen(outline_color, 2))
{
gr.DrawPath(thick_pen, wheel_path);
}
}
}
示例6: Flatten_Polygon
public void Flatten_Polygon ()
{
GraphicsPath path = new GraphicsPath ();
path.AddPolygon (new Point[4] {
new Point (0, 0), new Point (10, 10),
new Point (20, 20), new Point (40, 40)
});
GraphicsPath clone = (GraphicsPath) path.Clone ();
path.Flatten ();
ComparePaths (path, clone);
}
示例7: Flatten_Pie
public void Flatten_Pie ()
{
GraphicsPath path = new GraphicsPath ();
path.AddPie (0, 0, 100, 100, 30, 30);
GraphicsPath clone = (GraphicsPath) path.Clone ();
path.Flatten ();
CompareFlats (path, clone);
}
示例8: DrawTextOnPath
public void DrawTextOnPath()
{
PointF[] tmpPoints;
PointF[] points = new PointF[25001];
int count = 0;
GraphicsPath gp = new GraphicsPath(_pathdata.Points, _pathdata.Types) { FillMode = FillMode.Winding };
_regionList.Clear();
gp.Flatten(null, 1);
try
{
PointF tmpPoint = gp.PathPoints[0];
int i;
for (i = 0; i <= gp.PathPoints.Length - 2; i++)
{
if (gp.PathTypes[i + 1] == (byte)PathPointType.Start | (gp.PathTypes[i] & (byte)PathPointType.CloseSubpath) == (byte)PathPointType.CloseSubpath)
{
tmpPoints = GetLinePoints(gp.PathPoints[i], tmpPoint, 1);
Array.ConstrainedCopy(tmpPoints, 0, points, count, tmpPoints.Length);
count += 1;
tmpPoint = gp.PathPoints[i + 1];
}
else
{
tmpPoints = GetLinePoints(gp.PathPoints[i], gp.PathPoints[i + 1], 1);
Array.ConstrainedCopy(tmpPoints, 0, points, count, tmpPoints.Length);
count += tmpPoints.Length - 1;
}
}
tmpPoints = new PointF[count];
Array.Copy(points, tmpPoints, count);
points = CleanPoints(tmpPoints);
count = points.Length - 1;
DrawText(points, count);
}
catch (Exception ex)
{
LastError = ex;
}
}
示例9: GenerateAustPlusRandomEllipses
//---------------------------------------------------------------------
private void GenerateAustPlusRandomEllipses(int count)
{
subjects.Clear();
//load map of Australia from resource ...
_assembly = Assembly.GetExecutingAssembly();
polyStream = _assembly.GetManifestResourceStream("GuiDemo.aust.bin");
int len = (int)polyStream.Length;
byte[] b = new byte[len];
polyStream.Read(b, 0, len);
int polyCnt = BitConverter.ToInt32(b, 0);
int k = 4;
for (int i = 0; i < polyCnt; ++i)
{
int vertCnt = BitConverter.ToInt32(b, k);
k += 4;
Polygon pg = new Polygon(vertCnt);
for (int j = 0; j < vertCnt; ++j)
{
float x = BitConverter.ToSingle(b, k) * scale;
float y = BitConverter.ToSingle(b, k + 4) * scale;
k += 8;
pg.Add(new IntPoint((int)x, (int)y));
}
subjects.Add(pg);
}
clips.Clear();
Random rand = new Random();
GraphicsPath path = new GraphicsPath();
Point pt = new Point();
const int ellipse_size = 100, margin = 10;
for (int i = 0; i < count; ++i)
{
int w = pictureBox1.ClientRectangle.Width - ellipse_size - margin *2;
int h = pictureBox1.ClientRectangle.Height - ellipse_size - margin * 2 - statusStrip1.Height;
pt.X = rand.Next(w) + margin;
pt.Y = rand.Next(h) + margin;
int size = rand.Next(ellipse_size - 20) + 20;
path.Reset();
path.AddEllipse(pt.X, pt.Y, size, size);
path.Flatten();
Polygon clip = new Polygon(path.PathPoints.Count());
foreach (PointF p in path.PathPoints)
clip.Add(new IntPoint((int)(p.X * scale), (int)(p.Y * scale)));
clips.Add(clip);
}
}
示例10: Shape2Str
//.........这里部分代码省略.........
}
else
{
PathPart = String.Format(provider, " 0\nARC\n 100\nAcDbEntity\n{0:HAN} 8\n{5}\n 62\n{6:ACI}\n 100\nAcDbCircle\n 10\n{0:U}\n 20\n{1:U}\n 40\n{2:U}\n 100\nAcDbArc\n 50\n{3}\n 51\n{4}\n",
cx, m_FlowChart.DocExtents.Height - cy,rx, StartAngle , EndAngle, SHAPE_LAYER, crLine);
}
break;
case 29: // If shape element is bezier curve
BezierTemplate bt = et as BezierTemplate;
X = rect.X + rect.Width * (bt.Coordinates[0]/100);
Y = rect.Y + rect.Height* (bt.Coordinates[1]/100);
X1 = rect.X + rect.Width * (bt.Coordinates[2]/100);
Y1 = rect.Y + rect.Height* (bt.Coordinates[3]/100);
X2 = rect.X + rect.Width * (bt.Coordinates[4]/100);
Y2 = rect.Y + rect.Height* (bt.Coordinates[5]/100);
X3 = rect.X + rect.Width * (bt.Coordinates[6]/100);
Y3 = rect.Y + rect.Height* (bt.Coordinates[7]/100);
gr_temp.Reset();
gr_temp.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3);
gr.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3);
// Applying rotation if it's necessary
pts = RotatePoints(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), gr_temp);
gr_temp.Flatten();
PointF[] pts2 = gr_temp.PathData.Points.Clone() as PointF[];
PathPart = String.Format(provider, "0\nPOLYLINE\n{0:HAN} 100\nAcDbEntity\n8\n{0}\n 62\n{1:ACI}\n 100\nAcDb2dPolyline\n 66\n1\n 70\n4\n 75\n6\n{2}{3}0\nSEQEND\n 100\nAcDbEntity\n{0:HAN}",
SHAPE_LAYER,
crLine,
Pt2String(pts,crLine,SHAPE_LAYER,DxLineType.ltVertex, dash, 16),
Pt2String(pts2,crLine,SHAPE_LAYER,DxLineType.ltVertex, dash, 8));
break;
case 30: // If shape element is line
LineTemplate lt = et as LineTemplate;
X1 = rect.X + rect.Width * (lt.Coordinates[0]/100);
Y1 = rect.Y + rect.Height* (lt.Coordinates[1]/100);
X2 = rect.X + rect.Width * (lt.Coordinates[2]/100);
Y2 = rect.Y + rect.Height* (lt.Coordinates[3]/100);
gr_temp.Reset();
gr_temp.AddLine(X1,Y1,X2,Y2);
gr.AddLine(X1,Y1,X2,Y2);
// Applying rotation if it's necessary
pts = RotatePoints(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), gr_temp);
PathPart = Pt2String(pts, crLine,SHAPE_LAYER,DxLineType.ltSingle,DashStyle.Solid, 1);
break;
}
result+=PathPart;
}
示例11: CreateRoundedRectWithTitleRegionPath
/// <summary>
/// Creates a rectangular <see cref="GraphicsPath"/> with rounded edges, optionally with an open title
/// region specified by the parameters <paramref name="titleInset"/> and <paramref name="titleWidth"/>.
/// </summary>
/// <param name="baseRect">The rect which surrounds the created path.</param>
/// <param name="radiusX">The X radius of the rounded edges.</param>
/// <param name="radiusY">The Y radius of the rounded edges.</param>
/// <param name="withTitleRegion">If set to <c>true</c>, a title region will be left out.</param>
/// <param name="titleInset">Inset of the title region behind the corner. This parameter will only be used if
/// <paramref name="withTitleRegion"/> is set to <c>true</c>.</param>
/// <param name="titleWidth">Width of the title region to leave out. This parameter will only be used if
/// <paramref name="withTitleRegion"/> is set to <c>true</c>.</param>
public static GraphicsPath CreateRoundedRectWithTitleRegionPath(RectangleF baseRect, float radiusX, float radiusY,
bool withTitleRegion, float titleInset, float titleWidth)
{
GraphicsPath result = new GraphicsPath();
if (radiusX <= 0.0f && radiusY <= 0.0f || baseRect.Width == 0 || baseRect.Height == 0)
{
// if corner radius is less than or equal to zero, return the original rectangle
if (withTitleRegion)
{ // If we should leave out a title region, we need to do it manually, because we need to start next to the
// title.
titleWidth = Math.Min(titleWidth, baseRect.Width - 2 * titleInset);
// Right from the title to the upper right edge
result.AddLine(baseRect.Left + 2* titleInset + titleWidth, baseRect.Top,
baseRect.Right, baseRect.Top);
// Upper right edge to lower right edge
result.AddLine(baseRect.Right, baseRect.Top,
baseRect.Right, baseRect.Bottom);
// Lower right edge to lower left edge
result.AddLine(baseRect.Right, baseRect.Bottom,
baseRect.Left, baseRect.Bottom);
// Lower left edge to upper left edge
result.AddLine(baseRect.Left, baseRect.Bottom,
baseRect.Left, baseRect.Top);
// Upper left edge to the left side of the title
result.AddLine(baseRect.Left, baseRect.Top, baseRect.Left + titleInset, baseRect.Top);
}
else
result.AddRectangle(baseRect);
}
else
{
if (radiusX >= baseRect.Width / 2f)
radiusX = baseRect.Width/2f;
if (radiusY >= baseRect.Height / 2f)
radiusY = baseRect.Height/2f;
// create the arc for the rectangle sides and declare a graphics path object for the drawing
SizeF sizeF = new SizeF(radiusX * 2f, radiusY * 2f);
RectangleF arc = new RectangleF(baseRect.Location, sizeF);
if (withTitleRegion)
{
titleWidth = Math.Min(titleWidth, baseRect.Width - 2 * (radiusX + titleInset));
// Right of the title to the upper right edge
result.AddLine(baseRect.Left + radiusX + titleInset + titleWidth, baseRect.Top,
baseRect.Right - radiusX, baseRect.Top);
}
// Top right arc
arc.X = baseRect.Right - radiusX * 2f;
result.AddArc(arc, 270, 90);
// Bottom right arc
arc.Y = baseRect.Bottom - radiusY * 2f;
result.AddArc(arc, 0, 90);
// Bottom left arc
arc.X = baseRect.Left;
result.AddArc(arc, 90, 90);
// Top left arc
arc.Y = baseRect.Top;
result.AddArc(arc, 180, 90);
if (withTitleRegion)
// Upper left edge to the left side of the title
result.AddLine(baseRect.Left + radiusX, baseRect.Top, baseRect.Left + radiusX + titleInset, baseRect.Top);
else
result.CloseFigure();
}
result.Flatten();
return result;
}
示例12: Paint
/// <summary>
/// Repaints the form with cool background and stuff
/// </summary>
/// <param name="graph">The graphics object to paint to, the element will be drawn to 0, 0</param>
public override void Paint(Graphics graph)
{
//Draws Rectangular Shapes
if (Shape == ModelShape.Arrow)
{
_arrowPath = new GraphicsPath();
//Draws the basic shape
Pen arrowPen;
if (Highlight < 1)
arrowPen = new Pen(Color.Cyan, 3F);
else
arrowPen = new Pen(Color.Black, 3F);
//Draws the curved arrow
Point[] lineArray = new Point[4];
lineArray[0] = new Point(_startPoint.X, _startPoint.Y);
lineArray[1] = new Point(_startPoint.X - ((_startPoint.X - _stopPoint.X) / 3), _startPoint.Y);
lineArray[2] = new Point(_stopPoint.X - ((_stopPoint.X - _startPoint.X) / 3), _stopPoint.Y);
lineArray[3] = new Point(_stopPoint.X, _stopPoint.Y);
graph.DrawBeziers(arrowPen, lineArray);
_arrowPath.AddBeziers(lineArray);
_arrowPath.Flatten();
//Draws the arrow head
Point[] arrowArray = new Point[3];
arrowArray[0] = _stopPoint;
arrowArray[1] = new Point(_stopPoint.X - (5 * Math.Sign(_stopPoint.X - _startPoint.X)), _stopPoint.Y - 2);
arrowArray[2] = new Point(_stopPoint.X - (5 * Math.Sign(_stopPoint.X - _startPoint.X)), _stopPoint.Y + 2);
graph.DrawPolygon(arrowPen, arrowArray);
//Garbage collection
arrowPen.Dispose();
}
}
示例13: Flatten_Empty
public void Flatten_Empty ()
{
GraphicsPath path = new GraphicsPath ();
GraphicsPath clone = (GraphicsPath) path.Clone ();
// this is a no-op as there's nothing in the path
path.Flatten ();
ComparePaths (path, clone);
}
示例14: GenerateAustPlusRandomEllipses
//---------------------------------------------------------------------
private void GenerateAustPlusRandomEllipses(int count)
{
subjects.Clear();
//load map of Australia from resource ...
Assembly _assembly = Assembly.GetExecutingAssembly();
using (BinaryReader polyStream = new BinaryReader(_assembly.GetManifestResourceStream("GuiDemo.aust.bin")))
{
int polyCnt = polyStream.ReadInt32();
for (int i = 0; i < polyCnt; ++i)
{
int vertCnt = polyStream.ReadInt32();
Polygon pg = new Polygon(vertCnt);
for (int j = 0; j < vertCnt; ++j)
{
float x = polyStream.ReadSingle() * scale;
float y = polyStream.ReadSingle() * scale;
pg.Add(new IntPoint((int)x, (int)y));
}
subjects.Add(pg);
}
}
clips.Clear();
Random rand = new Random();
using (GraphicsPath path = new GraphicsPath())
{
const int ellipse_size = 100, margin = 10;
for (int i = 0; i < count; ++i)
{
int w = pictureBox1.ClientRectangle.Width - ellipse_size - margin * 2;
int h = pictureBox1.ClientRectangle.Height - ellipse_size - margin * 2 - statusStrip1.Height;
int x = rand.Next(w) + margin;
int y = rand.Next(h) + margin;
int size = rand.Next(ellipse_size - 20) + 20;
path.Reset();
path.AddEllipse(x, y, size, size);
path.Flatten();
Polygon clip = new Polygon(path.PathPoints.Count());
foreach (PointF p in path.PathPoints)
clip.Add(new IntPoint((int)(p.X * scale), (int)(p.Y * scale)));
clips.Add(clip);
}
}
}
示例15: GetLine
/// <summary>
/// Get the desired Rounded Rectangle path.
/// </summary>
private GraphicsPath GetLine(RectangleF baseRect)
{
float x1 = (float) X1;
float y1 = (float) Y1;
float x2 = (float) X2;
float y2 = (float) Y2;
float w = (float) Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
float ang = (y2 - y1) / (x2 - x1);
ang = (float) Math.Atan(ang);
ang *= (float) (180.0f / Math.PI);
GraphicsPath mPath = new GraphicsPath();
System.Drawing.Rectangle r = new System.Drawing.Rectangle((int) x1, (int) y1, (int) w, (int) StrokeThickness);
mPath.AddRectangle(r);
mPath.CloseFigure();
using (Matrix matrix = new Matrix())
{
matrix.RotateAt(ang, new PointF(x1, y1), MatrixOrder.Append);
matrix.Translate(baseRect.X, baseRect.Y, MatrixOrder.Append);
RectangleF bounds = mPath.GetBounds(matrix);
matrix.Scale(baseRect.Width / bounds.Width, baseRect.Height / bounds.Height);
mPath.Transform(matrix);
}
mPath.Flatten();
return mPath;
}