Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loading a Bitmap File

Started by ACAC May 23, 2002 at 3:10 PM 4 replies 300+ views
Original Post
ACAC
ACAC
Ive been working on a loading a bitmap code, i havnt been able to get it working the image is all skewed. www.btinternet.com/~ashley.canning/code.zip Thats the code, full project, the Load code is in CBitmap.cpp If anyone gets a spare 5 mins, could you take a look please?
sakky
sakky
This is how I use to load bitmaps until I started using DDUTIL that included with the DirectX7 SDK, and on down I think. The code is DDUTIL basicly does the same thang.


  

HRESULT LoadBitmapToSurface(IDirectDrawSurface7 *lpSurface,char *szBitmap,HINSTANCE g_hInst)
{
HDC mainDC;
HDC BitmapDC;
HBITMAP hBitmap;
HRESULT hRet;

hRet = lpSurface->GetDC(&mainDC);
if(FAILED(hRet))
return(hRet);

hBitmap = (HBITMAP) LoadImage(g_hInst,szBitmap,IMAGE_BITMAP,0,0LR_LOADFROMFILE); // Load the Bitmap from file


BitmapDC = CreateCompatibleDC(mainDC);

SelectObject(BitmapDC,hBitmap);

BitBlt(mainDC,0,0,BITMAP_WIDTH,BITMAP_HEIGHT,BitmapDC,0,0SRCCOPY);

hRet = lpSurface->ReleaseDC(mainDC);
if(FAILED(hRet))
return(hRet);

DeleteObject(hBitmap);
DeleteDC(BitmapDC);
}


Theres lots missing to this, like getting the actual width and height of the bitmap. Plus other error checking. Hope this helps a little bit. I think you should look at some of the tutorials on GameDev about loading a bitmap to a surface. Theres tutorials about this on GameTutorials.com that are for Win32. Loading a Bitmap to a surface is basicly the same as loading a bitmap and blitting it in win32. You just use the GetDC() and ReleaseDC() methods from the DirectDrawSurface object, Like you would regularly use Win32s GetDC() and ReleaseDC(). If you run into any problems with colors, make sure when you blitting you bitmap to the DirectDrawSurface you use SRCCOPY.
Take back the internet with the most awsome browser around, FireFox
ACAC
ACAC
well the whole point of me writing my own code was to gain knowlege of loading bitmaps
Big Sassy
Big Sassy
Refer to this thread here. It''s right up your alley

***********************
          
Cybertron
Cybertron
Bitmap files have an lPitch too. The length of each line (in bytes) is always divisible by 4

So don't just loop through the whole data, copy it one scanline at a time using the lpithc of the file and dest surface. You will need to write a new loop though to take this into account

and make sure you use a proper 16-bit RGB macro (not lamothe's crap one!)

#define _RGB565(r,g,b) ((b>>3) | ((g>>2) << 5) | ((r>>3) << 11))

There, it takes 0-255 for the R, G and B paramiter (this is what is in the bitmap file)

Good start though, you wrote it all yourself!


[edited by - Cybertron on May 23, 2002 8:21:56 PM]
Big Sassy
Big Sassy
Are you refering to my posts Cybertron? Did you even read the whole thread?

EDIT - Also, bitmap files don't have a lPitch. DirectDraw surfaces have a lPitch. You may be confusing lPitch with the DWORD padding that comes with properly saved bitmaps.

***********************
          

[edited by - Big Sassy on May 23, 2002 9:05:56 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.