我需要实现读取心电数据(.ecg格式,二进制文件),然后每读16位转成十进制存到一个short型的数组中(关于数据说一下,我要显示30秒的动态波形,每一秒有360个点,一个十进制数据代表一个点的纵坐标的值,也就是说要绘360*30个点),将这些点连接起来就是那条动态曲线。以下是我根据别人的代码修改过的,但是波形不动,请各位牛人帮我看一下,我在这里不胜感激!(网格部分无所谓,主要是波形)namespace WindowsFormsApplication4
{
public partial class Form8 : Form
{
public Form8()
{
InitializeComponent();
}
int 网格间距 = 12; //网格间距
int 网格偏移 = 0; //网格偏移
Pen 网格颜色 = new Pen(Color.FromArgb(0x00, 0x80, 0x40));
Pen 曲线颜色 = new Pen(Color.Lime);
private void Form8_Paint(object sender, PaintEventArgs e)
{
short[] data = new short[10800];
FileStream fs = new FileStream("c://a.ecg", FileMode.Open);
BinaryReader r = new BinaryReader(fs);
for (int i = 0; i < 10800; i++)
{
data[i] = r.ReadInt16();
}
fs.Close();
e.Graphics.FillRectangle(Brushes.Black, 0,0,800,640);
for (int i = 800 - 网格偏移; i >= 0; i -= 网格间距)
e.Graphics.DrawLine(网格颜色, i, 0, i, 640);
//绘制横线
for (int i = 640; i >= 0; i -= 网格间距)
e.Graphics.DrawLine(网格颜色, 0, i, 800, i);
short First = data[10800 - 1];
for (int i = 10800 - 2; i >= 0; i--)
{
short Second = data[i]; e.Graphics.DrawLine(曲线颜色,
800 - (10800 - i), First / 3,
800 - (10800 - i) - 1, Second / 3); First = Second;
}
} private void Form8_Load(object sender, EventArgs e)
{
DoubleBuffered = true;
this.timer1.Interval = 100;
this.timer1.Start();
} private void timer1_Tick(object sender, EventArgs e)
{
网格偏移 = (网格偏移 + 1) % 网格间距;
Invalidate();
}
private void Form8_Resize(object sender, EventArgs e)
{
Invalidate();
}
}
}我怀疑是不是private void timer_Tick这里少点东西??
{
public partial class Form8 : Form
{
public Form8()
{
InitializeComponent();
}
int 网格间距 = 12; //网格间距
int 网格偏移 = 0; //网格偏移
Pen 网格颜色 = new Pen(Color.FromArgb(0x00, 0x80, 0x40));
Pen 曲线颜色 = new Pen(Color.Lime);
private void Form8_Paint(object sender, PaintEventArgs e)
{
short[] data = new short[10800];
FileStream fs = new FileStream("c://a.ecg", FileMode.Open);
BinaryReader r = new BinaryReader(fs);
for (int i = 0; i < 10800; i++)
{
data[i] = r.ReadInt16();
}
fs.Close();
e.Graphics.FillRectangle(Brushes.Black, 0,0,800,640);
for (int i = 800 - 网格偏移; i >= 0; i -= 网格间距)
e.Graphics.DrawLine(网格颜色, i, 0, i, 640);
//绘制横线
for (int i = 640; i >= 0; i -= 网格间距)
e.Graphics.DrawLine(网格颜色, 0, i, 800, i);
short First = data[10800 - 1];
for (int i = 10800 - 2; i >= 0; i--)
{
short Second = data[i]; e.Graphics.DrawLine(曲线颜色,
800 - (10800 - i), First / 3,
800 - (10800 - i) - 1, Second / 3); First = Second;
}
} private void Form8_Load(object sender, EventArgs e)
{
DoubleBuffered = true;
this.timer1.Interval = 100;
this.timer1.Start();
} private void timer1_Tick(object sender, EventArgs e)
{
网格偏移 = (网格偏移 + 1) % 网格间距;
Invalidate();
}
private void Form8_Resize(object sender, EventArgs e)
{
Invalidate();
}
}
}我怀疑是不是private void timer_Tick这里少点东西??
解决方案 »
- C# 生成图片 ie显示正常,firefox 不显示
- 关于list的添加问题
- 请问查询表中所有列,去掉重复的列sql怎么查?
- 关于加密解密
- C++中的指针类型,在C#中要用什么类型替换啊?
- 我以前做pb的,现在在C# winform里面,第三次发同样的贴,怎么在datagrid里面查询,编辑,更新access数据库
- 用C#如何判断获取的进程不是系统进程???(up有分)
- GGJJ:怎样让按钮成为(弹出带有2个条件的页面)?
- 为什么自己做的一个纯黑色和纯白色的鼠标指针在空间中全部显示的都是一坨黑?
- DataGrid的style设置
- 如何把一个100行1000列的二维数组存进SQL2005数据库中
- List<T> 快速的统计!
short First = data[10800 - 1];
for (int i = 10800 - 2; i >= 0; i--)这两行改成这样试试:
short First = data[10800 - 1 - 网格偏移];
for (int i = 10800 - 2 - 网格偏移; i >= 0; i--)
short[] data = new short[10800];放在方法外面,在 Paint方法里面直接调用。
然后在timer_tick中修改这个变量
paint中从这个变量的位置开始画图
public partial class WaveForm : Form
{
const int POINTS_PER_SECOND = 360; short[] _data; public WaveForm()
{
InitializeComponent(); _data = GetWaveData(30);
} /// <summary>
/// 由于没有数据文件,此方法生成一条SIN曲线的数据。
/// </summary>
/// <param name="seconds">以秒为单位的曲线长度。</param>
/// <returns></returns>
private static short[] GetWaveData(int seconds)
{
int length = seconds * POINTS_PER_SECOND;
short[] array = new short[length];
for (int i = 0; i < length; i++)
{
array[i] = (short)Math.Round(100.0 * Math.Sin((double)(i % 360) * (Math.PI / 180.0)));
} return array;
} protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
RenderWaveLine(e);
} private void RenderWaveLine(PaintEventArgs e)
{
Graphics g = e.Graphics; g.TranslateTransform(20f, Height / 2f); GraphicsPath path = new GraphicsPath(); int length = _data.Length;
List<PointF> points = new List<PointF>(length);
for (int i = _offset; i < length; i++)
{
points.Add(new PointF(i - _offset, _data[i]));
}
path.AddLines(points.ToArray()); g.DrawPath(Pens.Lime, path); path.Dispose();
} int _offset; private void timer1_Tick(object sender, EventArgs e)
{
_offset = (_offset + 36) % _data.Length;
this.Invalidate();
}
}
另外别用GDI+的反走样,医生不习惯看的。
{
int length = seconds * POINTS_PER_SECOND;
short[] array = new short[length];
FileStream fs = new FileStream("c://a.ecg", FileMode.Open);
BinaryReader r = new BinaryReader(fs);
for (int i = 0; i < length; i++)
{
array[i] = r.ReadInt16();
}
fs.Close();
return array;
}
这样写貌似根本看不到曲线,麻烦您解答一下~
刚才仔细看你提供的代码,原来在绘图的时候是缩小3倍,那你也可以这样试试:
for (int i = _offset; i < length; i++)
{
points.Add(new PointF(i - _offset, _data[i] / 3f));
}
{
get { return textBox1.Text; }
}然后在子窗体(该绘图窗体)也设定了一个public string dir,是这样接值的:
dir = ((Form7)this.Owner).passText;/*(form7)是父窗体*/, dir变量取代了路径位置,可是运行时提示找不到'c:\dir' 请问您这该如何改呢?
private void button2_Click(object sender, EventArgs e)
{
Form frm = new Form8();
frm.Owner = this;
frm.Show();
this.Hide();
}
楼猪神经病.
从你描述的来看,传值应该没有问题,那就要确认在textBox1里输入的内容没有问题,再调试一下,看dir这个变量和textBox1里的内容是否相同。
另外,你这种传值方法不太可靠,假如Owner不是Form7而是其它类型怎么办呢?最好是在Form8里设置一个参数并由调用者传入,可以在构造函数里写,例如:
class Form8
{
// 这是原来的构造函数
public Form8()
{
InitializeComponent();
} // 设置一个全局变量存放文件路径
string _filename; public Form8(string filename)
: this() // 调用原来的构造函数
{
if (!System.IO.File.Exists(filename))
throw new System.IO.FileNotFoundException();
_filename = filename;
}
}
[code]
这样,在Form7这样写:[code=C#]
private void button2_Click(object sender, EventArgs e)
{ string filename = textBox1.Text;
if (System.IO.File.Exists(filename))
{
Form8 frm = new Form8(filename); // 在构造函数里把文件名传进去
frm.FormClosed += (s, e1) => { this.Show(); } // 这是为了在form8关闭了以后把自己自显示出来
frm.Show();
this.Hide();
}
else
MessageBox.Show("文件" + filename + "未找到。");
}