您现在的位置是:首页 > 文章详情

WPF特效-绘制实时2D激光雷达图

日期:2018-08-13点击:842
原文: WPF特效-绘制实时2D激光雷达图

接前两篇:

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<double>的数据集合处理成DrawingImage然后得到RenderTargetBitmap,再转换为System.Drawing.Bitmap 再转换为Emgu.CV.Image。 所以后续的实验中直接就使用了Emgu绘图,处理完成后转换为BitmapSource在WPF界面呈现。其实完全使用WPF的绘图方式也能实现实时雷达图效果。

如:


绘制效率也挺不错的。上面的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<double> 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 < ltDistances.Count; i++) { double lDistance = ltDistances[i]; double dDegree = -120d + i * this.IntervalDegree; double dRadian = Utilitys.ConvertToRads(dDegree); double dX = this.ImgMainZm.Width / 2d + lDistance * Math.Sin(dRadian); if (dX < 0) dX = 0; if (dX > 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

原文链接:https://yq.aliyun.com/articles/677872
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章