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

Started by
1 comment, last by JSCFaith 23 years, 9 months ago
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
Advertisement

    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
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.
This Space for rent.

This topic is closed to new replies.

Advertisement