Loading image

Hi:

How I can read an image that it’s stored on a resource file *.rc in VC++

Thanks,

RVO

Hi:

How I can read an image that it’s stored on a resource file *.rc in VC++

I had to look this one up. :slight_smile:
It looks like you can load the image using the windows LoadBitmap() function.
Once you get an HBITMAP, you have to get at the BITMAP structure it references
and just copy the data to an SDL surface. It looks like you can use the
GetObject() function to get at the BITMAP structure:

HBITMAP hBmp = LoadBitmap(...);
BITMAP bmp; 

// Retrieve the bitmap color format, width, and height. 
GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp);

Then you’ll need to get at the bits using GetDIBits() and an HDC created
using GetHDC(NULL) …

Does anybody have code that does this (or a different approach)?

Here’s some more information that might help:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_7zfp.asp

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Try something like that, it’s a code snipet from my clases, it do the
job for me…
cSurface::cSurface(const int resID, char *type)
{
SDL_RWops *tmp;
HRSRC hres;
HGLOBAL hnd;
int rsz;
tmp = NULL;

hres = FindResource(NULL, MAKEINTRESOURCE(resID), type);

if (hres)
hnd = LoadResource(NULL, hres);
else
{
m_showWinErrorMsg(GetLastError());
return;
}

if (hnd)
{
hnd = LockResource(hnd);

if (!hnd)
{
m_showWinErrorMsg(GetLastError());
return;
}
else
{
rsz = SizeofResource(NULL, hres);

if (!rsz)
{
m_showWinErrorMsg(GetLastError());
return;
}
}
}
else
{
m_showWinErrorMsg(GetLastError());
return;
}

tmp = SDL_RWFromMem(hnd, rsz);
SDLSurface *srf = IMG_Load_RW(tmp, 1);
if (srf == NULL)
fprintf(stderr, “Can’t load image from resource : %s\n”,
SDL_GetError());

DeleteObject(hnd);
}> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Rodolfo Victoria
Sent: Saturday, October 05, 2002 3:37 AM
To: sdl at libsdl.org
Subject: [SDL] Loading image

Hi:

How I can read an image that it’s stored on a resource file *.rc in VC++

Thanks,

RVO