I understand double buffering a panel basically means all the drawing is done to a buffer and then the buffer is copied directly to the drawing surface.
I am drawing to a Bitmap, and then drawing that Bitmap to my panel, using Graphics.DrawImage
, so that I have the Bitmap saved and can make updates to it without having to re-do all the draw operations.
Is this the same as Double Buffering the panel, as far as the flickering of the panel is concerned?
Or, should I be double buffering and re-doing all my drawing, if that means I will get lower flicker?
Edit:
I am plotting points with DrawLine
, the points are generated dynamically and I don't store a point once I am done plotting it. If I do Double Buffer, I will also have to incur the memory overhead of storing all the points I plot.

- 1,513
- 1
- 18
- 36
-
Do you have flickering? – Lasse V. Karlsen Jun 24 '17 at 15:55
-
@LasseV.Karlsen Yes, I do have some flickering – Priyank Jun 24 '17 at 15:59
-
1Yes, the system knows better than your code. Whether redrawing or drawing a bitmap is better depends on the number of drawing operations. I found it best to cache the 1st in a bitmap and redraw the last 100-500 operations.. – TaW Jun 24 '17 at 16:03
-
Wouldn't having to re-draw everything each time affect performance? @TaW – Priyank Jun 24 '17 at 16:05
-
Drawing n pixels from the bitmap or m from the drawing code - what are n and m ?? – TaW Jun 24 '17 at 16:05
-
1Note: What I meant by 'caching' is : Set the Panel.BackgroundImage when the redrawing gets too slow to display the result of the 1st operations and only redraw the last ones. Every so and so ops you would create a new backimage to include more ops in it and redraw less.. So you would never do a DrawImage for the whole panel.. – TaW Jun 24 '17 at 16:19
-
@TaW I think the combination of the two comments you posted make up the answer to what I was looking for..I would be glad to accept it, if you were to post it as an answer! – Priyank Jun 24 '17 at 17:45
2 Answers
Double buffer should work a bit differently. Lets say while you modify buffer A, it should draw using buffer B; then when you start modifying buffer B, it should read from A.
So, the idea is to not write the buffer being read. Therefore, using external buffer and copying it to drawing buffer doesnt seem to be same as double buffer. Actually, it is possible to write buffer by copying external one while it is being read.

- 43
- 6
The optimal solution will mostly depend on what you draw, how many operations, how many pixels involved and the total size of the drawing surface.
One common example is a drawing program, where the user piles strokes upon strokes, each consisting of hundreds of points..
In general it is recommended to let the system take care of double-buffering the control you draw on. It will do a better job than you can hope for..
So you should re-draw in the Paint
event and not try to implement your own buffered bitmap drawing in order to get rid of flicker.
The flicker will go away but with a huge number of drawing operations this will be slow and cause lags.
To avoid lags you can combine the best of both methods:
draw the graphics until they get too many; it depends on the drawing calls (basically the number of pixels involved) and the speed of your system whether you can afford a few hundred or tens of thousands of drawing calls before you notice lags, say after
N
calls.Then cache the first
N
drawing calls by drawing into a bitmap which you then set as thePanel's BackgroundImage
. All drawing fromN+1
will still be drawn onto the panel's surface in thePaint
event. When you reach2*N
you create another version of the caching image, start surface drawing at2*N+1
and so forth..

- 53,122
- 8
- 69
- 111