日期:2014-05-19  浏览次数:21155 次

graphics 画图闪烁的问题
graphics画矩形,用timer事件画的,然后都refresh,矩形多了闪烁,怎么解决?

------解决方案--------------------
Dim bmp As New Bitmap(Width, Height)
Dim g As Graphics = Graphics.FromImage(bmp)

g.DrawRect1(……)
g.DrawRect2(……)
g.DrawRect3(……)

PictureBox1.CreateGraphics.DrawImage(bmp, 0, 0)

这么处理一下好点
------解决方案--------------------
Bitmap bit=null;
bit=new Bitmap( , );
Graphics g= Graphics.FromImage(b2);
g.Clear(Color.White);

g.Draw...............
Graphics g = Graphics.FromHwnd(this.Handle);
g.DrawImage(b0,10,10);

------解决方案--------------------
利用GDI+的双缓冲技术来提高绘图效率
 1、在内存中建立一块“虚拟画布”:

Bitmap bmp = new Bitmap(600, 600);

  2、获取这块内存画布的Graphics引用:

Graphics g = Graphics.FromImage(bmp);

  3、在这块内存画布上绘图:

g.FillEllipse(brush, i * 10, j * 10, 10, 10);

  4、将内存画布画到窗口中

this.CreateGraphics().DrawImage(bmp, 0, 0);

绝对可行的~试过了~
------解决方案--------------------
//private void panel1_Paint(object sender, PaintEventArgs e)
//{

//Bitmap bmp = new Bitmap(300, 450);
//Graphics gra = Graphics.FromImage(bmp);
// Graphics gra = this.panel1.CreateGraphics();
//for (int i = 0; i < rectangles.Count; i++)
//{
//gra.DrawRectangle(new Pen(Color.Black, 1), rectangles[i]);
//}
//this.panel1.CreateGraphics().DrawImage(bmp, 0, 0);
//}

private void timer1_Tick(object sender, EventArgs e)
{ j++;
y+=30;
Rectangle rec = new Rectangle(x, y, 30, 30);
rectangles.Add(rec);
if (rectangles.Count > j + 1)
{
rectangles.RemoveAt(j);
}


//this.panel1.Invalidate();

Bitmap bmp = new Bitmap(300, 450);
Graphics gra = Graphics.FromImage(bmp);
// Graphics gra = this.panel1.CreateGraphics();
for (int i = 0; i < rectangles.Count; i++)
{
gra.DrawRectangle(new Pen(Color.Black, 1), rectangles[i]);
}
this.panel1.CreateGraphics().DrawImage(bmp, 0, 0);

}