Clipper 라이브러리를 사용하여 그래픽 경로를 수정하려고합니다.Clipper 라이브러리를 사용하여 경로 확대 및 채우기 방법
나는 윤곽선/획을 나타내는 너비 목록이 있습니다. 나는 가장 큰 것부터 시작하여 가장 작은 것으로 나아가고 싶다.
이 예를 들어, 우리는 20 (10) 내 그래픽 경로을 먹고 싶어의 폭이 2 스트로크를 추가합니다, 새로운 그래픽 경로로 20 개 픽셀하여 오프셋/확장합니다. 원래 경로를 변경하고 싶지 않습니다. 그런 다음 새로운 그래픽 경로를 단색으로 채 웁니다.
다음으로 원본 그래픽 경로를 가져 와서 10 픽셀 씩 새 그래픽 경로로 확장/오프셋합니다. 나는이 새로운 길을 다른 색으로 채우고 싶다.
그런 다음 원본 경로를 다른 색으로 채 웁니다.
이 작업을 수행하는 올바른 방법은 무엇입니까? 나는이 작업을 시도하기 위해 만든 다음과 같은 방법을 사용하지만 제대로 작동하지 않습니다.
private void createImage(Graphics g, GraphicsPath gp, List<int> strokeWidths)
{
ClipperOffset pathConverter = new ClipperOffset();
Clipper c = new Clipper();
gp.Flatten();
foreach(int strokeSize in strokeWidths)
{
g.clear();
ClipperPolygons polyList = new ClipperPolygons();
GraphicsPath gpTest = (GraphicsPath)gp.Clone();
PathToPolygon(gpTest, polyList, 100);
gpTest.Reset();
c.Execute(ClipType.ctUnion, polyList, PolyFillType.pftPositive, PolyFillType.pftEvenOdd);
pathConverter.AddPaths(polyList, JoinType.jtMiter, EndType.etClosedPolygon);
pathConverter.Execute(ref polyList, strokeSize * 100);
for (int i = 0; i < polyList.Count; i++)
{
// reverses scaling
PointF[] pts2 = PolygonToPointFArray(polyList[i], 100);
gpTest.AddPolygon(pts2);
}
g.FillPath(new SolidBrush(Color.Red), gpTest);
}
}
private void PathToPolygon(GraphicsPath path, ClipperPolygons polys, Single scale)
{
GraphicsPathIterator pathIterator = new GraphicsPathIterator(path);
pathIterator.Rewind();
polys.Clear();
PointF[] points = new PointF[pathIterator.Count];
byte[] types = new byte[pathIterator.Count];
pathIterator.Enumerate(ref points, ref types);
int i = 0;
while (i < pathIterator.Count)
{
ClipperPolygon pg = new ClipperPolygon();
polys.Add(pg);
do
{
IntPoint pt = new IntPoint((int)(points[i].X * scale), (int)(points[i].Y * scale));
pg.Add(pt);
i++;
}
while (i < pathIterator.Count && types[i] != 0);
}
}
private PointF[] PolygonToPointFArray(ClipperPolygon pg, float scale)
{
PointF[] result = new PointF[pg.Count];
for (int i = 0; i < pg.Count; ++i)
{
result[i].X = (float)pg[i].X/scale;
result[i].Y = (float)pg[i].Y/scale;
}
return result;
}