Including image files...?

Is there any way to include image files in an application, without
actually keeping all the files with the app? Unless I’m missing
something, I had a method that should have worked. I opened the image
in Notepad, copied everything, then created a file with fstream,out of
the data from Notepad. This did not work. I tried to open the file with
MSPaint after creating it with fstream, but it gave errors. Any reasons
why this doesn’t work, or any better methods of doing so? I’m running
Windows XP Home, using Microsoft Visual C++ 6.0.

Colin Hart wrote:

Is there any way to include image files in an application, without
actually keeping all the files with the app? Unless I’m missing
something, I had a method that should have worked. I opened the image
in Notepad, copied everything, then created a file with fstream,out of
the data from Notepad. This did not work. I tried to open the file with
MSPaint after creating it with fstream, but it gave errors. Any reasons
why this doesn’t work, or any better methods of doing so? I’m running
Windows XP Home, using Microsoft Visual C++ 6.0.

If you wont be porting it off windows, you can put any files you want
into your EXE through resource files.

You could also find or write a small tool which will could take a file
and compile it into a object file as a void*. Well, the void* would
point to the data of course…

Actually there’s an easy way to do what you want in a portable manner.

Write a simple program that loads an image file to a SDL_Surface, then simply print the surface->pixels somewhat like this:—
int byteCount = ( surface->w * surface->h * surface->format->BytesPerPixel );
Uint8 *pixels = (Uint8 *)surface->pixels;

printf( “\n\t” );

for( int i = 0; i < byteCount; ++i )
{
printf( "0x%.2X, ", pixels[i] );

if( ( ( i + 1 ) % 15 ) == 0 )
{
	printf( "\n\t" );
}

}

It will output the pixels like this:
0xFF, 0x49, 0x36, 0x54, …
0x45, 0x66, …

You just have to copy and paste the result into an array in a source file:

Uint8 pixels[] = {
…paste here…
};

Then use the SDL_CreateRGBSurfaceFrom function to load the surface from memory.

HIH,
Thiago Bastos

Look up XPM; it’s designed for what you’re describing. It’s limited to
paletted surfaces without a lot of colors, but it’s good enough for a
lot of things, such as icons. The file format is a string declaration;
simply drop it in your source (or #include it) and throw the pointer at
SDL_image.On Mon, Feb 10, 2003 at 12:21:00AM -0300, Thiago Bastos wrote:

Actually there’s an easy way to do what you want in a portable manner.

Write a simple program that loads an image file to a SDL_Surface, then simply print the surface->pixels somewhat like this:


Glenn Maynard

Thiago Bastos wrote:

Actually there’s an easy way to do what you want in a portable manner.

Write a simple program that loads an image file to a SDL_Surface, then simply print the surface->pixels somewhat like this:


int byteCount = ( surface->w * surface->h * surface->format->BytesPerPixel );
Uint8 *pixels = (Uint8 *)surface->pixels;

printf( “\n\t” );

for( int i = 0; i < byteCount; ++i )
{
printf( "0x%.2X, ", pixels[i] );

if( ( ( i + 1 ) % 15 ) == 0 )
{
printf( “\n\t” );
}
}

It will output the pixels like this:
0xFF, 0x49, 0x36, 0x54, …
0x45, 0x66, …

You just have to copy and paste the result into an array in a source file:

Uint8 pixels[] = {
…paste here…
};

Then use the SDL_CreateRGBSurfaceFrom function to load the surface from memory.

HIH,
Thiago Bastos

thats basically what i suggested only i wasnt limiting it to images.

If you wont be porting it off windows, you can put any files you want
into your EXE through resource files.

You could also find or write a small tool which will could take a file
and compile it into a object file as a void*. Well, the void* would
point to the data of course…

Adding the images to the project as resource files did not work. Am I
doing something wrong, or will this not work for me? If not, then what
do I need for this ‘compile into object as void’ method?

Adding the images to the project as resource files did not work. Am I
doing something wrong, or will this not work for me? If not, then what
do I need for this ‘compile into object as void’ method?

Hi,

AFAIK, using resource files is no good for you.
I believe that by “compile into object as void” he meant you to do exactly what I explained in my last message.
Did you read it?

+Thiago