SelectObject() is used to set some property to a device context(DC). SelectObject() changes the specified property and returns old property value ( that is replaced with the new one). Following example shows how to set a new Bitmap object to a DC using SelectObject() function. Note that old Bitmap object is returned and stored in hOldBMP variable.
{
// PNG Test code here!!!
//
PNGLoader *pPNG = new PNGLoader("test.png");
HDC hDC = GetDC(hWnd);
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hOldBMP, hNewBMP;
pPNG->read();
// Display Image onto Screen for validation.
//
hNewBMP = CreateBitmap(pPNG->getWidth(), pPNG->getHeight(), 1, 32, pPNG->getBuffer());
hOldBMP = (HBITMAP)SelectObject(hMemDC, hNewBMP);
BitBlt(hDC, 0, 0, pPNG->getWidth(), pPNG->getHeight(), hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBMP);
DeleteObject(hNewBMP);
DeleteDC(hMemDC);
ReleaseDC(hWnd, hDC);
delete pPNG;
}
A collection of example source codes for c/c++ and ios and android platform. It also includes objective c.
Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts
Thursday, May 19, 2011
Monday, May 16, 2011
CreateCompatibleDC() example c c++
Following code fragment shows an example of CreateCompatibleDC() function. CreateCompatibleDC(hdc) function is used to create a device context(DC) that is compatible with the given dc(hdc). Most of the time, a compatible DC is created to hold a bitmap for a loaded image from another source. The image in the DC is then bitblit into the screen DC.[CreateCompatibleDC() example]
{
PNGWrapper *pPNG = new PNGWrapper("E:/Research/libpng/debug/testpng.png");
HDC hDC = GetDC(hWnd);
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hOldBMP, hNewBMP;
pPNG->readINDEX();
//pPNG->convert(PNG_PIXEL_BGRA_32);
// Display Image onto Screen for validation.
//
hNewBMP = CreateBitmap(pPNG->getWidth(), pPNG->getHeight(), 1, 32, pPNG->getBuffer());
hOldBMP = (HBITMAP)SelectObject(hMemDC, hNewBMP);
BitBlt(hDC, 0, 0, pPNG->getWidth(), pPNG->getHeight(), hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBMP);
DeleteObject(hNewBMP);
DeleteDC(hMemDC);
ReleaseDC(hWnd, hDC);
delete pPNG;
}
{
PNGWrapper *pPNG = new PNGWrapper("E:/Research/libpng/debug/testpng.png");
HDC hDC = GetDC(hWnd);
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hOldBMP, hNewBMP;
pPNG->readINDEX();
//pPNG->convert(PNG_PIXEL_BGRA_32);
// Display Image onto Screen for validation.
//
hNewBMP = CreateBitmap(pPNG->getWidth(), pPNG->getHeight(), 1, 32, pPNG->getBuffer());
hOldBMP = (HBITMAP)SelectObject(hMemDC, hNewBMP);
BitBlt(hDC, 0, 0, pPNG->getWidth(), pPNG->getHeight(), hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBMP);
DeleteObject(hNewBMP);
DeleteDC(hMemDC);
ReleaseDC(hWnd, hDC);
delete pPNG;
}
Subscribe to:
Posts (Atom)