Задача: из бмп-шки (см. вложение) выделить 12 подкартинок - HBITMAP-ов, используя функцию GetDIBits ().
Проблема: функция отрабатывает без ошибок, но результат нулевой.
Вот она (если кто осилит, буду премного благодарен, ну а сам я уже готов сдаваться
):
BOOL Pacman::InitializeGraphics ()
{
for (int i = 0; i < NUM_CREATURES; i++)
{
hbitComplexCreatures [i] = LoadBitmap (hInst, bitmapTitle [i]);
CheckForError (hbitComplexCreatures [i], TRUE);
}
BITMAP bm;
LPBITMAPINFO bmi;
HDC hdc = GetWindowDC (GetDesktopWindow());
for (int c = 0; c < NUM_CREATURES; c++)
{
if (GetObject (hbitComplexCreatures [c], sizeof (BITMAP), (LPVOID) & bm))
{
if (bmi = (LPBITMAPINFO) GlobalAlloc (GPTR,
sizeof (BITMAPINFOHEADER) + (bm.bmWidth * bm.bmHeight * sizeof (RGBQUAD))))
{
// Fill BITMAPINFO bmi struct
bmi->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
int ires = GetDIBits (hdc, hbitComplexCreatures [c],
0, bm.bmHeight, 0, bmi, DIB_RGB_COLORS);
CheckForError (&ires, ires);
int hcomplexbitSize = bmi->bmiHeader.biSizeImage;
char * hcomplexbits = 0;
if (hcomplexbits = (char *) GlobalAlloc (GPTR, hcomplexbitSize))
{
// Get current creature bitmap (complex) bits
ires = GetDIBits (hdc, hbitComplexCreatures [c],
0, bm.bmHeight, (LPVOID) hcomplexbits, bmi, DIB_RGB_COLORS);
CheckForError (&ires, ires);
int hbitWidth = bmi->bmiHeader.biWidth / NUM_SPRITES_INWIDTH;
int hbitHeight = bmi->bmiHeader.biHeight / NUM_SPRITES_INHEIGHT;
int hbitSize = hcomplexbitSize / NUM_SPRITES;
char * hbits = 0;
if (hbits = (char *) GlobalAlloc (GPTR, hbitSize))
{
// Divide complex creature bitmap
for (int m = 0; m < NUM_SPRITES_INHEIGHT; m++)
{
for (int n = 0; n < NUM_SPRITES_INWIDTH; n++)
{
for (int i = 0; i < hbitWidth; i++)
for (int j = 0; j < (hbitWidth * 4); j++)
{
hbits [i * (hbitWidth * 4) + j] = hcomplexbits [i * (hbitWidth * 4) + j + m * bm.bmWidth + n * hbitWidth];
}
BITMAPINFO * bmi2;
if (bmi2 = (LPBITMAPINFO) GlobalAlloc (GPTR,
sizeof (BITMAPINFOHEADER) + (hbitWidth * hbitHeight * sizeof (RGBQUAD))))
{
hbitCreatures [c] [m * NUM_SPRITES_INWIDTH + n] = CreateCompatibleBitmap (hdc, hbitWidth, hbitHeight);
bmi2->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
int ires = GetDIBits (hdc, hbitCreatures [c] [m * NUM_SPRITES_INWIDTH + n],
0, hbitHeight, 0, bmi2, DIB_RGB_COLORS);
CheckForError (&ires, ires);
int iresult = SetDIBits (hdc, hbitCreatures [c] [m * NUM_SPRITES_INWIDTH + n],
0, hbitHeight, (LPVOID) hbits, bmi2, DIB_RGB_COLORS);
GlobalFree (bmi2);
}
}
}
GlobalFree (bmi);
GlobalFree (hcomplexbits);
GlobalFree (hbits);
}
else
{
GlobalFree (bmi);
GlobalFree (hcomplexbits);
}
}
else
GlobalFree (bmi);
}
}
}
ReleaseDC (GetDesktopWindow (), hdc);
return TRUE;
}