Groups | Blog | Home
all groups > dotnet drawing api > july 2003 >

dotnet drawing api : Double buffering technique


Gerben van Loon
7/26/2003 3:37:08 PM
Hi,
=20
I just read this article about double buffering in GDI+ :
=20
http://windowsforms.net/articles/windowsformspainting.aspx
=20
He shows how to double buffer with this kind of code:
=20
//create our offscreen bitmap
Bitmap localBitmap =3D new =
Bitmap(ClientRectangle.Width,ClientRectangle.Height);
Graphics bitmapGraphics =3D Graphics.FromImage(localBitmap);
=20
//Draw things on the bitmap
=20
//push our bitmap forward to the screen
g.DrawImage(localBitmap, 0, 0);
=20
What he's doing here manually isn't that exactly what is done FOR you =
automatically by settings these styles:
=20
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
=20
So when I want to implement double buffering in my application I just =
have to set the above three styles? Or do I have to paint everything =
manually on a bitmap and then push that back to the form?
=20
Bob Powell [MVP]
7/26/2003 6:21:05 PM
[quoted text, click to view]
have to set the above three styles? Or do I have to paint everything =
manually on a bitmap and then push that back to the form?

Generally I would recommend using the built in ControlStyles for ease of =
use. It's completely transparent to your code and a no-brainer. The =
article in question discusses the process of double buffering to =
illustrate the why's and wherefores of the technique and so is =
interesting from that point of view.

There are also reasons why you may wish to perform your own double =
buffering which I discuss in an article on the subject which can be =
found in the tips and tricks section of my site.

http://www.bobpowell.net/tipstricks.htm

--=20
Bob Powell [MVP]
C#, System.Drawing

Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm

New Tips and Tricks include creating transparent controls
and how to do double buffering.

[quoted text, click to view]
Hi,
=20
I just read this article about double buffering in GDI+ :
=20
http://windowsforms.net/articles/windowsformspainting.aspx
=20
He shows how to double buffer with this kind of code:
=20
//create our offscreen bitmap
Bitmap localBitmap =3D new =
Bitmap(ClientRectangle.Width,ClientRectangle.Height);
Graphics bitmapGraphics =3D Graphics.FromImage(localBitmap);
=20
//Draw things on the bitmap
=20
//push our bitmap forward to the screen
g.DrawImage(localBitmap, 0, 0);
=20
What he's doing here manually isn't that exactly what is done FOR you =
automatically by settings these styles:
=20
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
=20
So when I want to implement double buffering in my application I just =
have to set the above three styles? Or do I have to paint everything =
manually on a bitmap and then push that back to the form?
=20
rollasoc
8/4/2003 4:59:45 PM
Bob,

From your reply then, if I manually perform the double buffering, does =
that imply that it would then be a bit stupid to apply the control =
styles as well?

rollasoc
[quoted text, click to view]
just have to set the above three styles? Or do I have to paint =
everything manually on a bitmap and then push that back to the form?

Generally I would recommend using the built in ControlStyles for ease =
of use. It's completely transparent to your code and a no-brainer. The =
article in question discusses the process of double buffering to =
illustrate the why's and wherefores of the technique and so is =
interesting from that point of view.

There are also reasons why you may wish to perform your own double =
buffering which I discuss in an article on the subject which can be =
found in the tips and tricks section of my site.

http://www.bobpowell.net/tipstricks.htm

--=20
Bob Powell [MVP]
C#, System.Drawing

Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm

New Tips and Tricks include creating transparent controls
and how to do double buffering.

[quoted text, click to view]
Hi,
=20
I just read this article about double buffering in GDI+ :
=20
http://windowsforms.net/articles/windowsformspainting.aspx
=20
He shows how to double buffer with this kind of code:
=20
//create our offscreen bitmap
Bitmap localBitmap =3D new =
Bitmap(ClientRectangle.Width,ClientRectangle.Height);
Graphics bitmapGraphics =3D Graphics.FromImage(localBitmap);
=20
//Draw things on the bitmap
=20
//push our bitmap forward to the screen
g.DrawImage(localBitmap, 0, 0);
=20
What he's doing here manually isn't that exactly what is done FOR =
you automatically by settings these styles:
=20
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
=20
So when I want to implement double buffering in my application I =
just have to set the above three styles? Or do I have to paint =
everything manually on a bitmap and then push that back to the form?
=20
Justin Weinberg
8/28/2003 1:05:43 PM
The SetStyle statements aren't supported in the Compact Framework - you =
must manually double buffer if you want the functionality. One reason =
to know about it at least.
[quoted text, click to view]
Hi,
=20
I just read this article about double buffering in GDI+ :
=20
http://windowsforms.net/articles/windowsformspainting.aspx
=20
He shows how to double buffer with this kind of code:
=20
//create our offscreen bitmap
Bitmap localBitmap =3D new =
Bitmap(ClientRectangle.Width,ClientRectangle.Height);
Graphics bitmapGraphics =3D Graphics.FromImage(localBitmap);
=20
//Draw things on the bitmap
=20
//push our bitmap forward to the screen
g.DrawImage(localBitmap, 0, 0);
=20
What he's doing here manually isn't that exactly what is done FOR you =
automatically by settings these styles:
=20
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
=20
So when I want to implement double buffering in my application I just =
have to set the above three styles? Or do I have to paint everything =
manually on a bitmap and then push that back to the form?
=20
james NO[at]SPAM tti-test.com
8/29/2003 3:02:51 AM
I have tried both these techniques.

Using

SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);

is certainly faster than using the techniques specified in

http://windowsforms.net/articles/windowsformspainting.aspx

although it does refer to this stuff. Using
ControlStyles.DoubleBuffer uses DIBSections which are an efficient way
to store bitmaps in memory. To use these manually you have to use
unmanaged GDI calls.
Sticking with managed code you are stuck with the slowness of the
approach taken in the the article.

AddThis Social Bookmark Button