最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#繪制實時曲線的方法

 更新時間:2022年02月17日 10:01:10   作者:一點晴  
這篇文章主要為大家詳細介紹了C#繪制實時曲線的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C#繪制實時曲線的具體代碼,供大家參考,具體內(nèi)容如下

1.要做一個調(diào)試工具,采集傳感器數(shù)據(jù)并顯示。繪制曲線注意坐標(biāo)反轉(zhuǎn),線條的張力即可。項目中的曲線是從右往左顯示的,線條的坐標(biāo)都放在list里了,效果如下圖:

2.上代碼

public class DrawingCurve
? ? {
? ? ? ? private Graphics graphics; //Graphics 類提供將對象繪制到顯示設(shè)備的方法
? ? ? ? private Bitmap bitmap; //位圖對象
? ? ? ? private int timeLine = 60;//60s
? ? ? ? private int canvasWidth = 600;//畫布長度
? ? ? ? private int sliceCount = 0;//刻度分段個數(shù) = timeLine
? ? ? ? private int xSlice = 10;//X軸刻度分端寬度
? ? ? ? private int xSliceHeight = 10;//X軸刻度高度
? ? ? ? private float tension = 0.5f; //張力系數(shù)
? ? ? ? private bool showX = true;
? ? ? ? private bool showY = true;
? ? ? ? private bool showZ = true;
?
? ? ? ? //Queue<PointF> que = new Queue<PointF>();//曲線fifo
? ? ? ? /// <summary>
? ? ? ? /// 構(gòu)造函數(shù)
? ? ? ? /// </summary>
? ? ? ? public DrawingCurve() {
? ? ? ? ? ? this.xSlice = this.canvasWidth / timeLine;
? ? ? ? }
?
? ? ? ? /// <summary>
? ? ? ? /// 繪制畫布
? ? ? ? /// </summary>
? ? ? ? /// <param name="width"></param>
? ? ? ? /// <param name="height"></param>
? ? ? ? /// <param name="points"></param>
? ? ? ? /// <returns></returns>
? ? ? ? public Bitmap DrawCanvas(int width, int height,List<float> points)
? ? ? ? {
? ? ? ? ? ? if (bitmap != null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? bitmap.Dispose();
? ? ? ? ? ? ? ? bitmap = null;
? ? ? ? ? ? }
?
? ? ? ? ? ? bitmap = new Bitmap(width, height);
? ? ? ? ? ? graphics = Graphics.FromImage(bitmap);
? ? ? ? ? ? graphics.FillRectangle(Brushes.Black, new Rectangle(0, 0, width, height));
? ? ? ? ? ? graphics.Transform = new Matrix(1, 0, 0, -1, 0, 0);//Y軸向上為正,X向右為
? ? ? ? ? ? graphics.TranslateTransform(0, height / 2, MatrixOrder.Append);
? ? ? ? ? ??
? ? ? ? ? ? Pen pen = new Pen(Color.Red, 1);
? ? ? ? ? ? pen.DashStyle = DashStyle.Custom;
? ? ? ? ? ? pen.DashPattern = new float[] { 2, 2 };
? ? ? ? ? ? graphics.DrawLine(pen, new Point(0, height / 4), new Point(width, height / 4));
? ? ? ? ? ? graphics.DrawLine(pen, new Point(0, height / -4), new Point(width, height / -4));
? ? ? ? ? ? graphics.DrawLine(new Pen(Color.GreenYellow,1), new Point(0, 0), new Point(width, 0));
? ? ? ? ? ? graphics.DrawString("0", new Font("Vendara",10), Brushes.White, new Point(0, -15));
? ? ? ? ? ? graphics.DrawString("+", new Font("Vendara", 10), Brushes.White, new Point(0, height / 4));
? ? ? ? ? ? graphics.DrawString("-", new Font("Vendara", 10), Brushes.White, new Point(0, height / -4-15));
? ? ? ? ? ? graphics.Transform = new Matrix(1, 0, 0, 1, 0, 0);//Y軸向上為正,X向右為
? ? ? ? ? ? graphics.TranslateTransform(0, height / 2, MatrixOrder.Append);
? ? ? ? ? ? graphics.DrawString("-59s", new Font("Vendara", 8), Brushes.White, new Point(0, height/2-15));
? ? ? ? ? ? graphics.DrawString("0s", new Font("Vendara", 8), Brushes.White, new Point(width-20, height / 2 - 15));
? ? ? ? ? ? for (int i = 0; i < timeLine; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int scale = i * xSlice;
? ? ? ? ? ? ? ? graphics.DrawLine(new Pen(new SolidBrush(Color.Blue)), 0 + scale, 0 + xSliceHeight * 0.1f, 0 + scale, 0 - xSliceHeight * 0.1f);
? ? ? ? ? ? }
?
? ? ? ? ? ? graphics.Transform = new Matrix(-1, 0, 0, -1, 0, 0);//Y軸向上為正,X向右為
? ? ? ? ? ? graphics.TranslateTransform(width, height / 2, MatrixOrder.Append);
?
? ? ? ? ? ? if (showX) DrawX(graphics, points);
? ? ? ? ? ? if (showY) DrawY(graphics, points);
? ? ? ? ? ? if (showZ) DrawZ(graphics, points);
? ? ? ? ? ? graphics.Dispose();
? ? ? ? ? ? return bitmap;
? ? ? ? }
?
? ? ? ? #region 繪制曲線
? ? ? ? private void DrawX(Graphics graphics, List<float> points)
? ? ? ? {
? ? ? ? ? ? Pen CurvePen = new Pen(Color.Cyan, 2);
? ? ? ? ? ? PointF[] CurvePointF = new PointF[points.Count];
? ? ? ? ? ? float keys = 0;
? ? ? ? ? ? float values = 0;
? ? ? ? ? ? for (int i = 0; i < points.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? keys = xSlice * i;
? ? ? ? ? ? ? ? values = 10 * (points[i] / 10);
? ? ? ? ? ? ? ? CurvePointF[i] = new PointF(keys, values);
? ? ? ? ? ? }
? ? ? ? ? ? graphics.DrawCurve(CurvePen, CurvePointF, this.tension);
? ? ? ? }
?
? ? ? ? private void DrawY(Graphics graphics, List<float> points)
? ? ? ? {
? ? ? ? ? ? Pen CurvePen = new Pen(Color.Purple, 2);
? ? ? ? ? ? PointF[] CurvePointF = new PointF[points.Count];
? ? ? ? ? ? float keys = 0;
? ? ? ? ? ? float values = 0;
? ? ? ? ? ? for (int i = 0; i < points.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? keys = xSlice * i;
? ? ? ? ? ? ? ? values = 10 * (points[i] / 10);
? ? ? ? ? ? ? ? CurvePointF[i] = new PointF(keys, values);
? ? ? ? ? ? }
? ? ? ? ? ? graphics.DrawCurve(CurvePen, CurvePointF, this.tension);
? ? ? ? }
?
? ? ? ? private void DrawZ(Graphics graphics, List<float> points)
? ? ? ? {
? ? ? ? ? ? Pen CurvePen = new Pen(Color.OrangeRed, 2);
? ? ? ? ? ? PointF[] CurvePointF = new PointF[points.Count];
? ? ? ? ? ? float keys = 0;
? ? ? ? ? ? float values = 0;
? ? ? ? ? ? for (int i = 0; i < points.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? keys = xSlice * i;
? ? ? ? ? ? ? ? values = 10 * (points[i] / 10);
? ? ? ? ? ? ? ? CurvePointF[i] = new PointF(keys, values);
? ? ? ? ? ? }
? ? ? ? ? ? graphics.DrawCurve(CurvePen, CurvePointF, this.tension);
? ? ? ? }
?
? ? ? ? /// <summary>
? ? ? ? /// 曲線開關(guān)
? ? ? ? /// </summary>
? ? ? ? /// <param name="_xyz"></param>
? ? ? ? /// <param name="show"></param>
? ? ? ? public void HideCurve(string _xyz,bool show) {
? ? ? ? ? ? switch (_xyz) {?
? ? ? ? ? ? ? ? case "x":
? ? ? ? ? ? ? ? ? ? showX = show;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case "y":
? ? ? ? ? ? ? ? ? ? showY = show;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case "z":
? ? ? ? ? ? ? ? ? ? showZ = show;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
?
? ? ? ? #endregion
? ? }

3.UI上使用ThreadStart進行調(diào)用,根據(jù)需要設(shè)置休眠時間即可,同時設(shè)置pictureBox顯示即可。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#用NPOI導(dǎo)出導(dǎo)入Excel幫助類

    C#用NPOI導(dǎo)出導(dǎo)入Excel幫助類

    這篇文章主要為大家詳細介紹了C#?NPOI導(dǎo)出導(dǎo)入Excel幫助類,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • 解決WCF不能直接序列化SqlParameter類型的問題

    解決WCF不能直接序列化SqlParameter類型的問題

    這篇文章介紹了解決WCF不能直接序列化SqlParameter類型的問題,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • C#、vb.net及SQL判斷指定年份是否為閏年的方法

    C#、vb.net及SQL判斷指定年份是否為閏年的方法

    這篇文章主要介紹了C#、vb.net及SQL判斷指定年份是否為閏年的方法,分別以三種方法實現(xiàn)了判斷閏年的功能,在進行項目開發(fā)中具有一定的參考借鑒價值,需要的朋友可以參考下
    2014-11-11
  • C#實現(xiàn)統(tǒng)計字數(shù)功能的方法

    C#實現(xiàn)統(tǒng)計字數(shù)功能的方法

    這篇文章主要介紹了C#實現(xiàn)統(tǒng)計字數(shù)功能的方法,較為詳細的分析了C#字數(shù)統(tǒng)計功能的原理與實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-08-08
  • .net使用cap實現(xiàn)消息異步處理

    .net使用cap實現(xiàn)消息異步處理

    CAP 是一個基于 .NET Standard 的 C# 庫,它是一種處理分布式事務(wù)的解決方案,同樣具有 EventBus 的功能,它具有輕量級、易使用、高性能等特點,本文給大家介紹了.net下使用cap實現(xiàn)消息異步處理,需要的朋友可以參考下
    2024-05-05
  • 通過C#實現(xiàn)裁剪PDF頁面功能

    通過C#實現(xiàn)裁剪PDF頁面功能

    在處理PDF文檔時,有時需要精確地裁剪頁面以適應(yīng)特定需求,比如去除廣告、背景信息或者僅僅是為了簡化文檔內(nèi)容,本文將指導(dǎo)如何使用免費.NET控件通過C#實現(xiàn)裁剪PDF頁面,需要的朋友可以參考下
    2024-09-09
  • 基于C#實現(xiàn)電腦系統(tǒng)掛機鎖

    基于C#實現(xiàn)電腦系統(tǒng)掛機鎖

    這篇文章主要為大家詳細介紹了如何利用C#實現(xiàn)電腦系統(tǒng)掛機鎖,文中的示例代碼講解詳細,對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
    2022-12-12
  • c#使用多線程的幾種方式示例詳解

    c#使用多線程的幾種方式示例詳解

    這篇文章主要介紹了c#使用多線程的幾種方式,通過示例學(xué)習(xí)c#的多線程使用方式,大家參考使用吧
    2014-01-01
  • C# Dynamic之:ExpandoObject,DynamicObject,DynamicMetaOb的應(yīng)用(下)

    C# Dynamic之:ExpandoObject,DynamicObject,DynamicMetaOb的應(yīng)用(下)

    本篇文章是對C#中ExpandoObject,DynamicObject,DynamicMetaOb的應(yīng)用進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • 快速了解c# 結(jié)構(gòu)體

    快速了解c# 結(jié)構(gòu)體

    這篇文章主要介紹了c# 結(jié)構(gòu)體的相關(guān)資料,文中示例代碼非常詳細,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07

最新評論

淮北市| 科技| 定陶县| 专栏| 神农架林区| 北宁市| 滕州市| 镇雄县| 普安县| 鹤山市| 吴旗县| 荥阳市| 巴马| 佛学| 白银市| 五家渠市| 河间市| 合阳县| 舒城县| 昌图县| 纳雍县| 永济市| 铜梁县| 策勒县| 苏州市| 杨浦区| 鄱阳县| 锦屏县| 定日县| 华亭县| 合肥市| 佛山市| 屯留县| 买车| 额济纳旗| 喜德县| 陆川县| 武隆县| 兴国县| 禄劝| 麦盖提县|