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
关注公众号
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
WPF特效-粒子动画
原文: WPF特效-粒子动画 WPF实现泡泡龙小游戏效果。 /// -Ball to Ball Collision - Detection and Handling /// http://stackoverflow.com/questions/345838/ball-to-ball-collision-detection-and-handling /// -Introduction - The World Of Bouncing Balls: /// http://www.ntu.edu.sg/home/ehchua/programming/java/J8a_GameIntro-BouncingBalls.html /// -How to: Render on a Per Frame Interval Using CompositionTarget /// http://msdn.microsoft.com/en-us/library/ms748838.aspx /// -The Physics of an Elastic Collision (Part 2): /...
-
下一篇
WPF实现选项卡效果(1)——使用AvalonDock
原文: WPF实现选项卡效果(1)——使用AvalonDock 简介 公司最近一个项目,软件采用WPF开发,需要实现类似于VS的选项卡(或者是浏览器的选项卡)效果。搜寻诸多资料后,发现很多同仁推荐AvalonDock这款开源控件。在其官方地址下载源码和Demo后,对其进行了初步的研究,初步实现了预期效果。 完整系列 ● 第一部分 ● 第二部分 ● 第三部分 在Git中下载工程源码 AvalonDocking的结构树 在下载的Demo中,我们可以发现AvalonDock的可视化结构树如下: <avalon:DockingManager x:Name="dockingManager"> <avalon:LayoutRoot> <avalon:LayoutPanel Orientation="Horizontal"> <avalon:LayoutDocumentPane DockWidth="300"> <avalon:LayoutAnchorable Title="Sample Tool Pane"> <TextBox /&...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- 设置Eclipse缩进为4个空格,增强代码规范
- 2048小游戏-低调大师作品
- CentOS6,CentOS7官方镜像安装Oracle11G
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Linux系统CentOS6、CentOS7手动修改IP地址
- SpringBoot2全家桶,快速入门学习开发网站教程


微信收款码
支付宝收款码