[英]How do we draw the solution of an offset polygon (inflated polygon), which was created by the Clipper Library (C#)? Use method DrawPolygons()?
我下載了 Clipper 庫,它允許我膨脹一個多邊形(偏移一個多邊形)。
“boundary_Points”是包含多邊形所有頂點的點數組。 下面是我正在使用的代碼。 不幸的是,在其他 Web 示例中使用的命令“DrawPolygons()”不作為函數存在。 有沒有辦法訪問這個命令或其他方式來繪制? 挑戰是:Clipper 庫使用 IntPoint 類型,就我而言,它不能在 GDI+ 中使用。 謝謝
using Path = List<IntPoint>;
using Paths = List<List<IntPoint>>;
boundary_path.AddLines(boundary_Points);
Region boundary_region = new Region(boundary_path);
g.DrawPath(pen1, boundary_path);
ClipperOffset co = new ClipperOffset();
Path boundary_point_list= new Path(); //contains all IntPoints of the polygon
co.AddPath(boundary_point_list, JoinType.jtRound, EndType.etClosedPolygon);
Paths solution = new Paths(); //
co.Execute(ref solution, -7.0);
DrawPolygons(solution, 0x40808080);
g.FillPolygon(Brushes.Olive, boundary_Points);
Clipper 不提供開箱即用的繪圖方法。 您必須通過您想使用的繪圖 API 將IntPoint
轉換為適合手動繪圖的任何格式。
我不使用 C#,但為了將IntPoint
轉換為 C++ 中基於浮點的類型,我在代碼中執行以下操作:
void scale_down_polypaths(const Paths &p_polypaths_in, Vector<Vector<Point2>> &p_polypaths_out) {
p_polypaths_out.clear();
for (int i = 0; i < p_polypaths_in.size(); ++i) {
const Path &polypath_in = p_polypaths_in[i];
Vector<Vector2> polypath_out;
for (int j = 0; j < polypath_in.size(); ++j) {
polypath_out.push_back(Point2(
static_cast<real_t>(polypath_in[j].X) / SCALE_FACTOR,
static_cast<real_t>(polypath_in[j].Y) / SCALE_FACTOR));
}
p_polypaths_out.push_back(polypath_out);
}
}
然后可以將結果傳遞給繪圖 API,但同樣,這取決於您使用的庫類型。 我沒有使用 GDI+ 的經驗。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.