tags:

views:

21

answers:

0

I want to copy a image on to another image where the target image contains the source in the center and rest background should be white. Here is my code

hBitmap = (HBITMAP)LoadImage(NULL, "logo.bmp", IMAGE_BITMAP, 0, 0,
                LR_LOADFROMFILE | /*LR_CREATEDIBSECTION | */ LR_DEFAULTSIZE);
GetObject( hBitmap, sizeof(BITMAP), &bm );
hDC = GetDC(GetActiveWindow());
HDC hMemDCSrc = CreateCompatibleDC( hDC );
HDC hMemDCDest = CreateCompatibleDC( hDC );
ReleaseDC(GetActiveWindow(), hDC);

SelectObject( hMemDCSrc, hBitmap );

hNewBitmap = CreateCompatibleBitmap(hMemDCSrc, rect.right, rect.bottom); 
SelectObject(hMemDCDest,hNewBitmap);

/* If destination rect is bigger than source, then do bitblt
if ( ( rect.right > bm.bmWidth ) && ( rect.bottom > bm.bmHeight ) )
{
BitBlt(  hMemDCDest,0,0,rect.right,rect.bottom,hMemDCSrc,0,0,WHITENESS);
BitBlt(  hMemDCDest,(rect.right-bm.bmWidth)/2,
            (rect.bottom - bm.bmHeight)/2,bm.bmWidth,bm.bmHeight,hMemDCSrc,0,0,SRCCOPY);
}
//Code to save the target in another file

My code works fine if the windows display mode is 32 bit. When the windows display mode is 16 bit my target image is half black and on the rest half the source image is repeadted twice.

Is there any change in some parameter require on 16 bit display mode.