Why the BufferedGraphics is slow in drawing?
I am using BufferedGraphics
on Form_Paint
event. It draws my required graphic but its too slow. Kindly give me the hints to solve this problem or any suggestions for better drawing techniques for the quick response.
BufferedGraphicsContext currentContext;
BufferedGraphics myBuffer;
// Gets a reference to the current BufferedGraphicsContext
currentContext = BufferedGraphicsManager.Current;
// Creates a BufferedGraphics instance associated with Form1, and with
// dimensions the same size as the drawing surface of Form1.
myBuffer = currentContext.Allocate(this.CreateGraphics(),
this.DisplayRectangle);
// Draws an ellipse to the graphics buffer.
myBuffer.Graphics.DrawImage(new Bitmap("C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\Pics\\Pic.jpg"), 0, 0);
myBuffer.Graphics.DrawEllipse(Pens开发者_如何学运维.Blue, 5, 90, 10, 10);
myBuffer.Graphics.DrawRectangle(Pens.Gold, 0, 7, 500, 500);
myBuffer.Graphics.DrawLine(Pens.Chartreuse, 0, 0, 800, 800);
myBuffer.Render();
This is a small example of the BufferedGraphics
, this works fine, but when the load increases, it slows down.
Try to use e.Graphics instead of this.CreateGraphics()
Just set the DoubleBuffered = true
and paint directly on form, it will perform much faster.
As noted you should use:
e.Graphics
Instead of:
this.CreateGraphics()
And about this line:
new Bitmap("C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\Pics\\Pic.jpg")
You are reading the image on every frame render, you should create a Bitmap outside Paint and just refer to it.
精彩评论