我想用 Win2D 库创建绘图。我已经完成了,但是当我想重绘更大的图纸时遇到了一些性能问题。这是我用来显示绘图的解决方案:
private Microsoft.Graphics.Canvas.Numerics.Vector2[] trianglePoints = new Microsoft.Graphics.Canvas.Numerics.Vector2[3];
private void RenderTriangle(List<Triangle> TriangleList)
{
using (var drawSession = renderTarget.CreateDrawingSession())
{
CanvasPathBuilder pathBuilder = new CanvasPathBuilder(Win2DCanvas);
foreach (Triangle triangle in TriangleList)
{
trianglePoints[0] = triangle.vertexA;
trianglePoints[1] = triangle.vertexB;
trianglePoints[2] = triangle.vertexC;
triangleGeometry = CanvasGeometry.CreatePolygon(Win2DCanvas, trianglePoints);
pathBuilder.AddGeometry(triangleGeometry);
}
drawSession.FillGeometry(CanvasGeometry.CreatePath(pathBuilder), color)
}
}
主要问题在于这一行:
triangleGeometry = CanvasGeometry.CreatePolygon(Win2DCanvas, trianglePoints);
创建大约 100 000 个多边形需要大约 6000 毫秒,这是令人难以置信的长时间。
你知道在 Win2D 中渲染大量三角形的更快方法吗?
我应该在 C++ 中创建多边形并将它们包装到 C# 或其他东西吗?
感谢您重播。