WPF特效-绘制实时2D激光雷达图
2021-03-23 03:24
阅读:530
接前两篇:
https://blog.csdn.net/u013224722/article/details/80738619
https://blog.csdn.net/u013224722/article/details/80738995
除了c# GDI 、Opencv(c++)、 c# Emgu绘图外,其实c#? WPF绘图功能也很强大。上文中之所以最终使用了Emgu绘图 ,只是因为在踩坑过程中尝试使用了Emgu的图像处理函数。 即首先将List
如:
绘制效率也挺不错的。上面的Gif,每秒10帧,每帧760个数据点。? 显示成弧形是因为我将数据截断了,即设定了最大值范围,超过了则等于设定的最大值。
#region Data Processing
private DrawingGroup DrawingGroup;
private void InitRadarVisualDraw()
{
this.DrawingGroup = new DrawingGroup();
DrawingImage oImgSrc = new DrawingImage(this.DrawingGroup);
this.ImgMainZm.Source = oImgSrc;
this.ImgMainZm.Height = this.RadarRadius;
this.ImgMainZm.Width = this.RadarRadius * 1920d / 1080d;
this.IntervalDegree = 240d / 760d;
}
private double RadarRadius = 1000d;
private double IntervalDegree = 0;
private void DrawRadarDatas(List ltDistances)
{
try
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
using (DrawingContext oDrawContent = this.DrawingGroup.Open())
{
oDrawContent.DrawRectangle(new SolidColorBrush(Colors.Black), new Pen(),
new Rect(0, 0, this.ImgMainZm.Width, this.ImgMainZm.Height));
oDrawContent.DrawEllipse(new SolidColorBrush(Colors.Green), new Pen(),
new Point(this.ImgMainZm.Width/2d, this.ImgMainZm.Height-10), 10, 10);
for (int i = 0; i this.ImgMainZm.Width)
dX = this.ImgMainZm.Width;
double dY = lDistance * Math.Cos(dRadian);
oDrawContent.DrawEllipse(new SolidColorBrush(Colors.Green), new Pen(),
new Point(dX, dY), 3, 3);
}
}
}));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
#endregion
下一篇:WPF特效-鱼游动动画3
评论
亲,登录后才可以留言!