c# - 在类似于 GDI - Arc() 方法的 WPF 应用程序中绘制 Arc 很热?
问题描述
我目前正在将 C++ 应用程序移植到 WPF。C++ 应用程序使用 GDI 进行图形绘制。为了绘制 Arc,在 C++ 应用程序中使用以下 GDI API。
WINAPI Arc( __in HDC hdc, __in int x1, __in int y1, __in int x2, __in int y2, __in int x3, __in int y3, __in int x4, __in int y4);
我需要将其转换为 WPF Arc。请帮忙
我已经尝试在 WPF 中绘制弧段。但输出与 GDI 绘图不匹配。
private void DrawArcSegment(double strokeThickness, SolidColorBrush colorBrush,
double left, double top, double right, double bottom,
double startArcX, double startArcY, double endArcX, double endArcY)
{
System.Windows.Shapes.Path arc = new System.Windows.Shapes.Path();
PathFigure figure = new PathFigure();
PathSegmentCollection segments = new PathSegmentCollection();
Point center = new Point(left + ((right - left) / 2), top + ((bottom - top) / 2));
double degrees = Math.Atan2(startArcY - center.Y, startArcX - center.X)
- Math.Atan2(endArcY - center.Y, endArcX - center.X);
degrees *= 57.2957795; // Convert from radians to degrees
bool isLargeArc = Math.Abs(degrees) > 180;
arc.Data = new PathGeometry();
figure.StartPoint = new Point((startArcX), (startArcY));
ArcSegment segment = new ArcSegment
{
Point = new Point(endArcX, endArcY),
Size = new Size((right - left) / 2, (bottom - top) / 2),
RotationAngle = 0,
IsLargeArc = isLargeArc,
SweepDirection = SweepDirection.Counterclockwise
};
segments.Add(segment);
figure.Segments = segments;
arc.Stroke = colorBrush;
arc.StrokeThickness = strokeThickness;
((PathGeometry)arc.Data).Figures.Add(figure);
drawingCanvas.Children.Add(arc);
}
解决方案
推荐阅读
- sql-server - 如何将 Azure SQL Server 数据库(数据)迁移到 kubernetes ms sql 数据库
- r - 绘制值范围从 -1 到 1 的固定切片饼图
- r - 条形图长度与值不匹配
- node.js - 复杂的 Mongoose 过滤器查询
- python-3.x - 通过创建单独的函数来解决 try-except 以应用于单行中的许多语句
- python - 如何获取 python selenium 中的所有数据?
- c++ - 在某些情况下使用 auto 作为返回类型和返回值 nullptr
- c# - C# - 通过 REF 从异步方法回调更新变量 - WebClient 类
- sql - 仅从 oracle sql 更新月份和年份的简单语句
- python - 熊猫风格:如何突出对角线元素