下面的代碼使在內存不足在DrawPath .NET 4.0(以及可能更高)。 我使用管理,而不是LineCap.Flat的LineCap.NoAnchor繞過它:
public void TestDrawPath()
{
PointF[] points = new PointF[13]
{
new PointF(0.491141558f, 1.53909028f),
new PointF(0.491141558f, 1.55148673f),
new PointF(0.4808829f, 1.56153619f),
new PointF(0.468228281f, 1.56153619f),
new PointF(0.4555736f, 1.56153619f),
new PointF(0.445314974f, 1.55148673f),
new PointF(0.445314974f, 1.53909028f),
new PointF(0.445314974f, 1.52669382f),
new PointF(0.4555736f, 1.51664436f),
new PointF(0.468228281f, 1.51664436f),
new PointF(0.4808829f, 1.51664436f),
new PointF(0.491141558f, 1.52669382f),
new PointF(0.491141558f, 1.53909028f)
};
byte[] types = new byte[13] { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 131 };
using (Bitmap bitmap = new Bitmap(2, 2))
using (Graphics g = Graphics.FromImage(bitmap))
{
using (Pen pen = new Pen(Color.Black))
using (GraphicsPath path = new GraphicsPath(points, types))
{
pen.StartCap = LineCap.NoAnchor;
pen.EndCap = LineCap.NoAnchor;
g.DrawPath(pen, path);
}
}
}
爲什麼呢?他們可以是相同的。如果我有一條封閉的線條或曲線...我需要檢查路徑上的所有點是否不是相同的點... – serhio
@serhio我認爲你不能擁有一條具有起點的單一行的路徑和一個相同的端點。 – LarsTech
一條路徑 - 單條線就是一條路徑。它可以是圓形,曲線,封閉線或任何其他幾何圖形。 – serhio