Advertisement

LoadBitmap()

Started by November 12, 2000 04:39 PM
1 comment, last by Je 24 years, 1 month ago
How do use LoadBitmap to load bitmaps in GDI. I really need to know this as soon as possible. Please give me many ways to do this.
Jame(#?)
Try looking in the Microsoft Windows SDK. All the information is in there.
http://www.crosswinds.net/~druidgames/resist.jpg
Advertisement
Here is some code from my Delphi game engine to load a bitmap into a DirectDraw surface.

var  hbmBitmap: HBITMAP;  hdcImage: HDC;  hdcSurf: HDC;  DDSD: TDDSurfaceDesc2;begin  Log(''Loading '' + AFilename);  FFilename := AFilename;  if (Length(AFilename) = 0) or (AFilename = ''[Primary]'') or (AFilename = ''[BackBuffer]'') then    Exit;  hbmBitmap := 0;  hdcImage := 0;  hdcSurf := 0;  { Auto-create the surface here if required from the bitmap dimensions. }  if not SurfaceValid then  begin    if GetBitmapSize then      CreateSurface    else      raise ESlyDXSurfaceError.Create(''LoadFromFile: Error retrieving bitmap info from file '' + FFilename);  end;  ZeroMemory(@DDSD, SizeOf(TDDSurfaceDesc2));  DDSD.dwSize := SizeOf(TDDSurfaceDesc2);  try    { Get the surface description. }    DDCheck(FSurface.GetSurfaceDesc(DDSD), ''LoadFromFile: Error getting surface description'');    { Try to load the bitmap. }    hbmBitmap := LoadImage(0, PChar(FFilename), IMAGE_BITMAP, DDSD.dwWidth,      DDSD.dwHeight, LR_LOADFROMFILE or LR_CREATEDIBSECTION);    if hbmBitmap = 0 then      raise ESlyDXSurfaceError.Create(''LoadFromFile: Error loading file '' + FFilename);    { Create a compatible DC and select the image into it. }    hdcImage := CreateCompatibleDC(0);    SelectObject(hdcImage, hbmBitmap);    { Get a DC for the surface. }    DDCheck(FSurface.GetDC(hdcSurf), ''LoadFromFile: Error getting a DC for the surface'');    { The BitBlt will perform format conversion as necessary. }    if not BitBlt(hdcSurf, 0, 0, DDSD.dwWidth, DDSD.dwHeight, hdcImage, 0, 0, SRCCOPY) then      raise ESlyDXSurfaceError.Create(''LoadFromFile: Error copying bitmap to surface DC'');  finally    { Clean up everything. }    if hdcSurf <> 0 then      FSurface.ReleaseDC(hdcSurf);    if hdcImage <> 0 then      DeleteDC(hdcImage);    if hbmBitmap <> 0 then      DeleteObject(hbmBitmap);  end;end;



Steve ''Sly'' Williams
Tools Developer
Krome Studios
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers

This topic is closed to new replies.

Advertisement