using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace CurvePlot
{
class CurveBMP
{
static Queue<byte> dataQueue = new Queue<byte>(1); //队列实现满屏后左移
Bitmap curveBMP; //绘制曲线的位图
Color bgColor,foreColor; //背景颜色和前景颜色
int width, height; //位图宽度和高度
public CurveBMP(Color bgColor, Color foreColor, int width, int height)
{
this.bgColor = bgColor;
this.foreColor = foreColor;
this.width = width;
this.height = height;
}
public Bitmap plot_curve(byte data)
{
curveBMP = new Bitmap(this.width, this.height); //重新准备位图
Graphics g = Graphics.FromImage(curveBMP);
dataQueue.Enqueue(data);
if (dataQueue.Count < 2) //不够两个点不能绘制
{
return curveBMP;
}
if (dataQueue.Count > this.width) //满屏后开始左移
{
dataQueue.Dequeue();
}
int i = 0;
Point[] pts = new Point[dataQueue.Count]; //通过点的连接绘制曲线
foreach (byte ele in dataQueue)
{
pts[i] = new Point(i, ele);
i++;
}
g.DrawLines(new Pen(foreColor),pts); //以前景颜色绘制曲线
g.Dispose();
return curveBMP;
}
}
}