1
votes

SOLVED: The problem was with ::CreateCompatibleBitmap ( hdc, 26, 26 ); I was creating a 26x26 bitmap where as the actual bitmap was 166x166, since the background color of the window and the bitmap was same so it wasn't visible when ::BitBlt ed. Such a stupid mistake.


This is a strange problem, few resource bmp images are not showing up when I ::BitBlt them, if I replace the images in question with a different bmp file(no change in the code) then it works. There are more bmp files in resource and they are working.
What could be the problem with the BMPs ?
I have checked with resource hacker and images are there in the executable.

Following is what I am doing in code.

Resource.rc

IDB_ANIMMAIN_1                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_1.bmp"
IDB_ANIMMAIN_2                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_2.bmp"
IDB_ANIMMAIN_3                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_3.bmp"
IDB_ANIMMAIN_4                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_4.bmp"
IDB_ANIMMAIN_5                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_5.bmp"
IDB_ANIMMAIN_6                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_6.bmp"
IDB_ANIMMAIN_7                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_7.bmp"
IDB_ANIMMAIN_8                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_8.bmp"
IDB_ANIMMAIN_9                      BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_9.bmp"
IDB_ANIMMAIN_10                     BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_10.bmp"
IDB_ANIMMAIN_11                     BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_11.bmp"
IDB_ANIMMAIN_12                     BITMAP  DISCARDABLE "E:\\image\\AnimMain\\AnimMain_12.bmp"

Resource.h

#define   IDB_ANIMMAIN_1                                    501
#define   IDB_ANIMMAIN_2                                    502
#define   IDB_ANIMMAIN_3                                    503
#define   IDB_ANIMMAIN_4                                    504
#define   IDB_ANIMMAIN_5                                    505
#define   IDB_ANIMMAIN_6                                    506
#define   IDB_ANIMMAIN_7                                    507
#define   IDB_ANIMMAIN_8                                    508
#define   IDB_ANIMMAIN_9                                    509
#define   IDB_ANIMMAIN_10                               510
#define   IDB_ANIMMAIN_11                               511
#define   IDB_ANIMMAIN_12                               512

main.cpp

std::vector < HBITMAP > bitmaps;

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_1 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_2 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_3 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_4 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_5 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_6 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_7 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_8 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_9 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_10 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_11 )  )   );

bitmaps.push_back (   ::LoadBitmap (  hInstance, MAKEINTRESOURCE ( IDB_ANIMMAIN_12 )  )   );

update:

HDC hdc = ::GetDC ( hwnd );

int i = 0;


while ( running )
{


    hbitmap = bitmaps [ i ];

    ::Sleep ( 200 );        paint ( hdc );


    i++;


    if (  i >= bitmaps.size (  )  )     i = 0;



}


::ReleaseDC ( hwnd, hdc );



return true;

Following is how I am doing the paint, the paint function is called from a loop that does the animation(for which the images are used), the this->hbitmap is updated in the loop.
If I change the IDB_ANIMMAIN_x in the ::LoadBitmap call to another resource identifier then it works, so I am sure the loop and onpaint(); are working.

onpaint:

HDC dcSkin = ::CreateCompatibleDC ( hdc );

HDC hMemDc = ::CreateCompatibleDC ( hdc );


HBITMAP hmemBmp = ::CreateCompatibleBitmap ( hdc, 26, 26  );


HBITMAP hOldMemBmp = (HBITMAP) ::SelectObject ( hMemDc, hmemBmp );


HBITMAP hOldSkinBmp = (HBITMAP) ::SelectObject ( dcSkin, this->hbitmap );


        //::MessageBox ( 0, "second", "jAnimationBig::paint", 0 );
        ::BitBlt ( hMemDc, 0, 0, width, height, dcSkin, 0, 0, SRCCOPY );

        ::BitBlt ( hdc, 0, 0, width, height, hMemDc, 0, 0, SRCCOPY );



::SelectObject ( hMemDc, hOldMemBmp );
::SelectObject ( dcSkin, hOldSkinBmp );


::DeleteObject ( hOldSkinBmp );
::DeleteObject ( hOldMemBmp );
::DeleteObject(  hmemBmp );
::DeleteDC ( hMemDc );
::DeleteDC ( dcSkin );
1
Check if the bitmaps have strange encoding - 16-bit, monochrome, or indexed, that is incompatible with your HDC. Or try to convert them to 24-bit colors with an image editor. Also, post the code that of the actual BitBlt and the creation of the HDC.sashoalm
@sashoalm I have updated the code above. And I do not know how to check the bitmaps :(StudentX
Check them with an image editor. Or Google about it, or something. Read this - paulbourke.net/dataformats/bitmapssashoalm
@sashoalm I checked with photoshop, they are RGB(not indexed) and 8bits/channel(so it makes them 24bits). :?StudentX
Did you check in the debugger if your bitmaps actually loaded correctly?Jonathan Potter

1 Answers

0
votes

SOLVED: The problem was with ::CreateCompatibleBitmap ( hdc, 26, 26 ); I was creating a 26x26 bitmap where as the actual bitmap was 166x166, since the background color of the window and the bitmap was same so it wasn't visible when ::BitBlt ed. Such a stupid mistake.