Hello everyone. I would like to know if it is possible to double buffer a .png image using GDI+ Can anyone help me? Below is the code I used to display a png image with alpha transparency, however, I do not know how to double buffer it! Please help.

  DrawPng (HDC hdc, HINSTANCE hinstance, HWND hwnd, int curbitmapvalue, int posX, int posY)
{ HRSRC hRsrc; 
  hRsrc = FindResource(hinstance, MAKEINTRESOURCE(curbitmapvalue), "PNG");
  HGLOBAL hImage;
  hImage = LoadResource(hinstance, hRsrc);
  LPVOID pImage;
  pImage = LockResource(hImage);
  HGLOBAL hBlock;
  IStream *pStream=NULL;
  int size= SizeofResource(hinstance, hRsrc);
  hBlock=GlobalAlloc(GHND, size);
  LPVOID pBlock;
  pBlock = GlobalLock(hBlock);
  memmove(pBlock,pImage, size);
  CreateStreamOnHGlobal(hBlock, FALSE, &pStream);
  Graphics graphics(hdc);
  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);
  pStream->Release();
  GlobalUnlock(hBlock);
  GlobalFree(hBlock);
}

I can't go into the details, but one way would be to create a compatible bitmap and HDC the same size as the images you want to store. So you'd have two bitmaps and two HDCs. One set is what you are using now and the other set is the "hidden offscreen" buffer.

Then you swap them backwards and forwards.

I use MFC, but it should be possible for raw Windows calls.

This article has been dead for over six months. Start a new discussion instead.