c# 实时波形闪烁问题 20
做一个实时波形控件,困扰几天了,用了双缓冲,刷新速度100ms,画了网格和一个正弦波一个方波(有定时器),还是有闪烁现象,网上看了很多办法,双缓冲,禁止背景重绘,都只是缓...
做一个实时波形控件,困扰几天了,用了双缓冲,刷新速度100ms,画了网格和一个正弦波 一个方波(有定时器),还是有闪烁现象,网上看了很多办法,双缓冲,禁止背景重绘,都只是缓解了闪烁。求大神帮看代码,或者远程协助,qq490816773注明下 谢谢!
主要绘制代码如下:外部每100ms刷新一次picturebox,更新m_CurrentPaintPoint(里面存了2条曲线,用list<PointF>描述)
private void pictureBoxGraph_Paint(object sender, PaintEventArgs e)
{
#region **绘图参数初始化**
int width = pictureBoxGraph.Width;
int height = pictureBoxGraph.Height;
Bitmap bmp = new Bitmap(width, height);
Graphics Grap = Graphics.FromImage(bmp);
Grap.Clear(Color.Black);
#endregion
#region **坐标变换,原点左下角,y向上增长**
Grap.TranslateTransform(0, height);//坐标原点变换,但是x,y还是往右增加,往上增加
Grap.ScaleTransform(1, -1); //使得y往上是增加
#endregion
#region**网格第一层绘制**
#region**第一层竖线绘制**
using (Pen gridLinePen = new Pen(new SolidBrush(Color.FromArgb(m_GridLineAlpha, Color.White)), 1f))
{
float i = 0, j = 0;
i = m_XBeginPaintPoint;
while (i < width)
{
Grap.DrawLine(gridLinePen, i, 0, i, height);
i += m_FirstXPixelInterval;
}
#endregion
#region**第一层横线绘制**
j = m_YBeginPaintPoint;
while (j < height)
{
Grap.DrawLine(gridLinePen, 0, j, width, j);
j += m_FirstYPixelInterval;
}
#endregion
#endregion
#region**网格第二层绘制**
#region**第二层竖线绘制**
gridLinePen.Color = (Color.FromArgb(m_GridLineAlpha / 3, Color.White));
i = m_XBeginPaintPoint;
while (i < width)
{
Grap.DrawLine(gridLinePen, i, 0, i, height);
i += m_SecondXPixelInterval;
}
#endregion
#region**第二层横线绘制**
j = m_YBeginPaintPoint;
while (j < height)
{
Grap.DrawLine(gridLinePen, 0, j, width, j);
j += m_SecondYPixelInterval;
}
}
#endregion
#endregion
#region **曲线绘制**
if (m_XPoint.Count != 0)
{
for (int i = 0; i < m_XPoint.Count; i++)
{
Grap.DrawLines(new Pen(m_LineColor[i], m_LineWidth[i]), m_CurrentPaintLines[i].ToArray());
}
}
e.Graphics.DrawImage(bmp, 0, 0);
#endregion
} 展开
主要绘制代码如下:外部每100ms刷新一次picturebox,更新m_CurrentPaintPoint(里面存了2条曲线,用list<PointF>描述)
private void pictureBoxGraph_Paint(object sender, PaintEventArgs e)
{
#region **绘图参数初始化**
int width = pictureBoxGraph.Width;
int height = pictureBoxGraph.Height;
Bitmap bmp = new Bitmap(width, height);
Graphics Grap = Graphics.FromImage(bmp);
Grap.Clear(Color.Black);
#endregion
#region **坐标变换,原点左下角,y向上增长**
Grap.TranslateTransform(0, height);//坐标原点变换,但是x,y还是往右增加,往上增加
Grap.ScaleTransform(1, -1); //使得y往上是增加
#endregion
#region**网格第一层绘制**
#region**第一层竖线绘制**
using (Pen gridLinePen = new Pen(new SolidBrush(Color.FromArgb(m_GridLineAlpha, Color.White)), 1f))
{
float i = 0, j = 0;
i = m_XBeginPaintPoint;
while (i < width)
{
Grap.DrawLine(gridLinePen, i, 0, i, height);
i += m_FirstXPixelInterval;
}
#endregion
#region**第一层横线绘制**
j = m_YBeginPaintPoint;
while (j < height)
{
Grap.DrawLine(gridLinePen, 0, j, width, j);
j += m_FirstYPixelInterval;
}
#endregion
#endregion
#region**网格第二层绘制**
#region**第二层竖线绘制**
gridLinePen.Color = (Color.FromArgb(m_GridLineAlpha / 3, Color.White));
i = m_XBeginPaintPoint;
while (i < width)
{
Grap.DrawLine(gridLinePen, i, 0, i, height);
i += m_SecondXPixelInterval;
}
#endregion
#region**第二层横线绘制**
j = m_YBeginPaintPoint;
while (j < height)
{
Grap.DrawLine(gridLinePen, 0, j, width, j);
j += m_SecondYPixelInterval;
}
}
#endregion
#endregion
#region **曲线绘制**
if (m_XPoint.Count != 0)
{
for (int i = 0; i < m_XPoint.Count; i++)
{
Grap.DrawLines(new Pen(m_LineColor[i], m_LineWidth[i]), m_CurrentPaintLines[i].ToArray());
}
}
e.Graphics.DrawImage(bmp, 0, 0);
#endregion
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询