Using MSVC Bitmap Resource with SDL_Image

The title should pretty much sum it up but here’s the scoop:

I want to embed a BMP file into my Win32 program. This is easy enough with
MSVC – simply import it into the resource file.

The question now is, how can I use the BMP in the embeded resource file with
SDL_Image?

Thanks for any help!

Leeor D. <leeor_net yahoo.com> writes:

I want to embed a BMP file into my Win32 program. This is easy enough with
MSVC – simply import it into the resource file.

The question now is, how can I use the BMP in the embeded resource file with
SDL_Image?

Since that solution isn’t portable to other platforms than Windows, I’d suggest
you look into RW_Ops on the documentation wiki at
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fRWops but I think it still requires
an external file. Secondly, the BMP loader is in the main SDL library rather
than the SDL_Image library. It should be possible with the RW_Ops functions to
read a BMP file from a buffer in memory.

No, it wouldn’t necessarily require an external file. You’re right - you can
load stuff that’s buffered in memory. What you’ll have to do is load your
bitmap resource as an HBITMAP using some sort of GDI method, then convert it
into a format that can be used by an SDL_RWops. I’m not sure quite how you
would go about doing that, but that’s the basics of it.

One option you might want to consider instead is to use XPM images and the
SDL_image library. The XPM format is actually a C source file (meaning it
works in C++), and you can build it right into your program by including it
like a header file. In the header file is a large array of pixel data, and
it supports transparency, too. There’s a method in the SDL_image library to
convert that structure into an SDL_Surface.

Good luck.On 7/26/07, Sam Crow wrote:

Leeor D. <leeor_net yahoo.com> writes:

I want to embed a BMP file into my Win32 program. This is easy enough
with
MSVC – simply import it into the resource file.

The question now is, how can I use the BMP in the embeded resource file
with
SDL_Image?

Since that solution isn’t portable to other platforms than Windows, I’d
suggest
you look into RW_Ops on the documentation wiki at
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fRWops but I think it still
requires
an external file. Secondly, the BMP loader is in the main SDL library
rather
than the SDL_Image library. It should be possible with the RW_Ops
functions to
read a BMP file from a buffer in memory.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


“If you see somebody who you don’t know getting into a crop duster that
doesn’t belong to you, report them.” – President George W. Bush

Yet another alternative is to use a program like “bin2c” (quite easy
to find using Google) to convert your .bmp file to a .c/.h file
containing a static array of chars (the original file’s contents).

Then you can use SDL’s RWops function to load the file from memory.

I did this recently when converting a DirectX app which used Win32
resources to SDL and it worked just great.

Pete> One option you might want to consider instead is to use XPM images and the

SDL_image library. The XPM format is actually a C source file (meaning it
works in C++), and you can build it right into your program by including it
like a header file. In the header file is a large array of pixel data, and
it supports transparency, too. There’s a method in the SDL_image library to
convert that structure into an SDL_Surface.

Good luck.

On 7/26/07, Sam Crow wrote:

Leeor D. <leeor_net yahoo.com> writes:

I want to embed a BMP file into my Win32 program. This is easy enough
with

MSVC – simply import it into the resource file.

The question now is, how can I use the BMP in the embeded resource file
with

SDL_Image?

Since that solution isn’t portable to other platforms than Windows, I’d
suggest
you look into RW_Ops on the documentation wiki at
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fRWops but I
think it still requires
an external file. Secondly, the BMP loader is in the main SDL library
rather
than the SDL_Image library. It should be possible with the RW_Ops
functions to
read a BMP file from a buffer in memory.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


“If you see somebody who you don’t know getting into a crop duster that
doesn’t belong to you, report them.” – President George W. Bush


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yet another alternative is to use a program like “bin2c” (quite easy
to find using Google) to convert your .bmp file to a .c/.h file
containing a static array of chars (the original file’s contents).

Then you can use SDL’s RWops function to load the file from memory.

I use that too.

Here is how:
image = SDL_LoadBMP_RW (SDL_RWFromMem (img, imgsize), 1);Am Friday, dem 27. Jul 2007 schrieb Peter Mackay:


AKFoerster

Andreas K. Foerster <list akfoerster.de> writes:

Yet another alternative is to use a program like “bin2c” (quite easy
to find using Google) to convert your .bmp file to a .c/.h file
containing a static array of chars (the original file’s contents).

Then you can use SDL’s RWops function to load the file from memory.

I use that too.

Here is how:
image = SDL_LoadBMP_RW (SDL_RWFromMem (img, imgsize), 1);

Thanks all for your suggestions. As for the non-portable comment, I know it’s
not portable and I didn’t intend it to be. Not that method at least.

  • Leeor> Am Friday, dem 27. Jul 2007 schrieb Peter Mackay:

Leeor D. <leeor_net yahoo.com> writes:

The title should pretty much sum it up but here’s the scoop:

I want to embed a BMP file into my Win32 program. This is easy enough with
MSVC – simply import it into the resource file.

The question now is, how can I use the BMP in the embeded resource file with
SDL_Image?

Thanks for any help!

Again, thank you all for your suggestions.

I went with the Bin2C suggestion because I can embed any resource file such
as images, WAV’s and so on. This also makes it portable without the need to
include extra files.

So thanks again everyone for the support!

  • Leeor