Class2.cs
资源名称:wlll.rar [点击查看]
上传用户:zpsczj
上传日期:2022-02-13
资源大小:4436k
文件大小:5k
源码类别:
网络截获/分析
开发平台:
Visual C++
- using System.Collections.Generic;
- using System.Text;
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Drawing;
- using System.IO;
- namespace WindowsApplication1
- {
- /**/
- /// <summary>
- /// DrawClass 的摘要说明
- /// </summary>
- public class DrawClass
- {
- public DrawClass()
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- }
- public MemoryStream draw(float[] ds, float[] dx, float[] dz)
- {
- //取得记录数量
- int count = ds.Length;
- //记算图表宽度
- int wd = 80 + 20 * (count - 1);
- //设置最小宽度为200
- if (wd < 200) wd = 200;
- //生成Bitmap对像
- Bitmap img = new Bitmap(wd, 200);
- //生成绘图对像
- Graphics g = Graphics.FromImage(img);
- //定义黑色画笔
- Pen Bp = new Pen(Color.Black);
- //定义红色,蓝色,金色三种画笔
- Pen Rps = new Pen(Color.Red);
- Pen Rpx = new Pen(Color.Blue);
- Pen Rpz = new Pen(Color.Gold);
- //定义银灰色画笔
- Pen Sp = new Pen(Color.Silver);
- //定义大标题字体
- Font Bfont = new Font("Arial", 12, FontStyle.Bold);
- //定义一般字体
- Font font = new Font("Arial", 6);
- //定义大点的字体
- Font Tfont = new Font("Arial", 9);
- //绘制底色
- g.DrawRectangle(new Pen(Color.White, 200), 0, 0, img.Width, img.Height);
- //定义黑色过渡型笔刷
- LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Black, Color.Black, 1.2F, true);
- //定义蓝色过渡型笔刷
- LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);
- g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
- //绘制竖坐标线
- for (int i = 0; i < count; i++)
- {
- g.DrawLine(Sp, 20 + 20 * i, 10, 20 + 20 * i, 170);
- }
- //绘制时间轴坐标标签
- string st;
- for (int i = count - 1; i >= 0; i -= 2)
- {
- if (i == count - 1)
- {
- st = DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
- }
- else
- {
- int j = i;
- st = j.ToString();
- }
- g.DrawString(st, font, brush, 20 + 20 * i, 180);
- }
- //绘制横坐标线
- for (int i = 0; i < 10; i++)
- {
- g.DrawLine(Sp, 20, 10 + 16 * i, 20 + 20 * (count - 1), 10 + 16 * i);
- int s = 500 - 50* i ;
- //绘制发送量轴坐标标签
- g.DrawString(s.ToString(), font, brush, 10, 10 + 16 * i);
- }
- //绘制竖坐标轴
- g.DrawLine(Bp, 20, 10, 20, 170);
- //绘制横坐标轴
- g.DrawLine(Bp, 20, 170, 20 + 20 * (count - 1), 170);
- //定义曲线转折点
- Point[] p = new Point[count];
- Point[] q = new Point[count];
- Point[] o = new Point[count];
- for (int i = 0; i < count; i++)
- {
- p[i].X = 20 + 20 * i;
- q[i].X = 20 + 20 * i;
- o[i].X = 20 + 20 * i;
- p[i].Y = 170 - Convert.ToInt32(ds[i]) * 16 / 50;
- q[i].Y = 170 - Convert.ToInt32(dx[i]) * 16 / 50;
- o[i].Y = 170 - Convert.ToInt32(dz[i]) * 16 / 50;
- }
- //绘制曲线
- g.DrawLines(Rps, p);
- g.DrawLines(Rpx, q);
- g.DrawLines(Rpz, o);
- for (int i = 0; i < 1; i++)
- {
- //绘制记录点的数据量
- g.DrawString(ds[i].ToString(), font, Bluebrush, p[i].X, p[i].Y - 10);
- g.DrawString(dx[i].ToString(), font, Bluebrush, q[i].X, q[i].Y - 10);
- g.DrawString(dz[i].ToString(), font, Bluebrush, o[i].X, o[i].Y - 10);//绘制记录点
- g.DrawRectangle(Rps, p[i].X - 1, p[i].Y - 1, 2, 2);
- g.DrawRectangle(Rpx, q[i].X - 1, q[i].Y - 1, 2, 2);
- g.DrawRectangle(Rpz, o[i].X - 1, o[i].Y - 1, 2, 2);
- }
- //保存绘制的图片
- MemoryStream stream = new MemoryStream();
- img.Save(stream, ImageFormat.Jpeg);
- return stream;
- }
- }
- }