Archived

This topic is now archived and is closed to further replies.

Creating 24 bit image and rectifing it to 16bit..

This topic is 6364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, Well if someone could tell me how I could load a 24bit image in Directx and rectify it to 16bit so I can use it on a 16 surface. So could someone please tell me how or lead me somewhere that does tell me how. I read a tutorial on Gamedev but It didnt really tell you how, so could someone please help me? thanks. James, Later

Share this post


Link to post
Share on other sites

    

char *file;
HBITMAP hBitmap;
LPDIRECTDRAWSURFACE7 surface;

// Load the bitmap

hBitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE | LR_LOADFROMFILE);
// Create surface



// Set up the stucture with the correct details

ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bitmap.bmWidth;
ddsd.dwHeight = bitmap.bmHeight;
// Attempt to create surface

if ((lpdd->CreateSurface(&ddsd, surface, NULL)) != DD_OK)
{
return NULL;
}
// Attempt to create surface

if (surface == NULL)
{
// Release the bitmap and return failure to caller

DeleteObject(hBitmap);
return NULL;
}
else
{
// Get a device context for our surface

surface->GetDC(&hdc);

// Create a compatible device context

HDC bitmap_dc = CreateCompatibleDC(hdc);

// Blit the bitmap to the surface

SelectObject(bitmap_dc, hBitmap);
BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, bitmap_dc, 0, 0, SRCCOPY);

// Release the DCs

surface->ReleaseDC(hdc);
DeleteDC(bitmap_dc);
}
// Clear bitmap

DeleteObject(hBitmap);







This is a funtion I use to grab 24 bit BMP's, I use a 16 bit surface and it converts them automatically. Use this during initialization since it uses the Windows GDI and is SLOW!

CHIP

Edited by - Chipcrap on July 14, 2000 9:26:36 PM

Share this post


Link to post
Share on other sites
Personally I would just load a 16 bit image to start with, it''s less of a headach and also you will know exactly how it''s going to look. Changing the color depth may end up giving you some wierd colors where you don''t want them. It''s easier to just change the color depth in a paint program and fix it up then trying to make sure it is going to look right in the code.

Retired Pokemon Master of Prgramming Problems

I already had them all.

Share this post


Link to post
Share on other sites