Advertisement

Help with loading bitmaps

Started by August 20, 2000 10:35 PM
0 comments, last by OoMMMoO 24 years, 4 months ago
Can someone please email an example of loading a bitmap in directx,that explains the file I/O and drawing it on the surface? my email address is brdn69@hotmail.com
I used the idea from "DirectX 7 in 24 Hours" to create this function, works great!

            LPDIRECTDRAWSURFACE7 BitmapSurface(LPCTSTR filename, LPDIRECTDRAW7 &rLocalDD, int lowColor, int highColor){	HDC hdc;	HBITMAP hbitmap;	LPDIRECTDRAWSURFACE7 surface;	//Load image to handle	hbitmap = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0,		LR_DEFAULTSIZE | LR_LOADFROMFILE);	//If fail return Null	if (!hbitmap)	{		return(NULL);	}//end if	//Get the bitmap's size	BITMAP bitmap;	GetObject(hbitmap, sizeof(bitmap), &bitmap);	int surfwidth = bitmap.bmWidth;	int surfheight = bitmap.bmHeight;	HRESULT ddrval;		//Setup surface for creation	DDSURFACEDESC2 ddsd;	ZeroMemory(&ddsd, sizeof(ddsd));	ddsd.dwSize = sizeof(ddsd);	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;	ddsd.dwWidth = surfwidth;	ddsd.dwHeight = surfheight;	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = lowColor;	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = highColor;	ddrval = rLocalDD->CreateSurface(&ddsd, &surface, NULL);	//If failed, clean up and return Null	if (ddrval != DD_OK)	{		DeleteObject(hbitmap);		return(NULL);	}	//Bit the temp DC to the surface's dc and return the surface	else	{		surface->GetDC(&hdc);		HDC bitDC = CreateCompatibleDC(hdc);		SelectObject(bitDC, hbitmap);		BitBlt(hdc, 0, 0, surfwidth, surfheight, bitDC, 0, 0, SRCCOPY);		surface->ReleaseDC(hdc);		DeleteDC(bitDC);	}//end if	DeleteObject(hbitmap);		//Return success	return(surface);}            



To use it:

LPDIRECTDRAW7 lpDD;
LPDIRECTDRAWSURFACE7 lpOffScreenSurface;

//Assuming you have created DirectDraw object and let lpDD
//points to it

lpOffScreenSurface = BitmapSurface(filename, lpDD, 0, 0);



Edited by - vbisme on August 20, 2000 12:23:09 AM

This topic is closed to new replies.

Advertisement