当在d2d中绘制带路径几何和弧段的弧时,与其他框架相比,会出现一些故障。我用d2d和wpf wpf vs d2d绘制的弧创建了一个缩放版本。我已经在direct2d中标记了未正确绘制的区域。有人知道是什么造成了这样的图纸吗?
示例代码(SharpDX):
private static void TestRender(WindowRenderTarget renderTarget)
{
var geo = new PathGeometry(d2dFactory);
var sink = geo.Open();
Vector2 off = new Vector2(40.0f, 70.0f);
var arc_1 = new ArcSegment()
{
ArcSize = ArcSize.Small,
RotationAngle = 0,
Point = off,
Size = new Size2F(22, 22),
SweepDirection = SweepDirection.CounterClockwise
};
sink.BeginFigure(new SharpDX.Mathematics.Interop.RawVector2(84, 70), FigureBegin.Filled);
sink.AddArc(arc_1);
sink.EndFigure(FigureEnd.Open);
sink.Close();
StrokeStyle strokeStyle = new StrokeStyle(d2dFactory, new StrokeStyleProperties()
{
DashCap = CapStyle.Flat,
DashStyle = DashStyle.Solid,
LineJoin = LineJoin.Miter,
StartCap = CapStyle.Flat,
EndCap = CapStyle.Flat,
MiterLimit = 0,
DashOffset = 0
}, new float[0]);
var testBrush = new SharpDX.Direct2D1.SolidColorBrush(
renderTarget,
new SharpDX.Mathematics.Interop.RawColor4(1.0f, 0.0f, 0.0f, 1.0f),
new SharpDX.Direct2D1.BrushProperties
{
Opacity = 1.0f,
}
);
renderTarget.DrawGeometry(geo, testBrush, 10, strokeStyle);
geo.Dispose();
sink.Dispose();
}
在挖了一下之后,我发现如果我将起点移到y方向的一半“像素”,一切看起来都不错。现在的问题是如何编程确定需要转换哪些坐标。 此外,我想知道wpf是如何做到这一点的。我知道UseLayoutRounding和SnapToPixels。我很感兴趣他们(MS)如何为各种形状做这件事。