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条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Dcoker安装(在线仓库),最新的服务器搭配容器使用
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- SpringBoot2全家桶,快速入门学习开发网站教程
- Docker安装Oracle12C,快速搭建Oracle学习环境
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- CentOS8编译安装MySQL8.0.19
- MySQL数据库在高并发下的优化方案
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作