GDI + double buffering

I managed to achieve double buffering using GDI, but not with GDI +. I would like to display a png image without making it flicker. In addition, at some point I would also like to achieve animation with png images using GDI +, so knowing how to double the buffer with GDI + is mandatory.

I managed to get the png image into the Image object via ISTREAM: here is the part of my code that will help you understand where I am having problems:

memmove(pBlock,pImage, size); CreateStreamOnHGlobal(hBlock, FALSE, &pStream); Graphics graphics(memDC); Image image(pStream); int image_width; int image_height; image_width= image.GetWidth(); image_height=image.GetHeight(); graphics.DrawImage(&image, posX,posY, image_width, image_height); BitBlt(hdc, 0, 0, image_width, image_height, memDC, 0, 0, SRCCOPY); 

Note. If I draw a png image directly on the DC (hdc) screen, it displays a fine. However, when I try to first draw an image in memDC and then blt that memDC on the DC screen, the image does not appear!

Can someone point me in the right direction, how should someone double the buffer using GDI plus? thank you

+4
source share
1 answer

I think your problem may be how you create your memDC - do you use CreateCompatibleDC () to create this to make sure it is hdc compatible, what are you doing BitBlt () in?

I answered a question similar to this one before doing double buffering, and you may find the answer useful:

Accelerating GDI on Windows 7 / Drawing to a Bitmap Memory Card

There is code that I used quite a bit for the double buffer with GDI, but I draw into a bitmap using GDI or GDI +. It seemed to me that it is very useful to use GDI, because for some operations (especially related to bitmaps of functions) it is much faster than GDI +, but GDI + makes some things much easier, therefore it gives the best of both worlds.

+2
source

All Articles