Why BufferedGraphics is Slow in Drawing Using C #

I am using BufferedGraphics for the Form_Paint function. Its draw my required graphics, but its too slow. Please give me hints to solve this problem or offer me any other painting technique for a 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 BufferedGraphics, which works fine, but when load increases slow down.

+3
source share
2 answers

Try using e.Graphics instead of this.CreateGraphics ()

+1
source

Just set DoubleBuffered = trueand draw directly on the form, it will work much faster.

0
source

Source: https://habr.com/ru/post/1751159/


All Articles