Including .png Files When Compiled

Hello all,

I am currently coding a 2D game in Visual Studio 2013. All of the .png graphics are saved in an absolute directory (for example, "C:/gfx/example.png"). Although this works for testing the application on my own system, I would one day like to release it (although it won't be commercial, as I am just learning). I could put all the of the image files in a relative folder, but I do not like the idea of my graphics being out in the open like that.

Is it possible to compile these images into the application itself? I had been researching resource files on Google, but I am still not completely sure if this is what I need to be using. Even if it is, I am using the express version of VS, so I do not have access to the editor. If resource files are what I am looking for, do I have to purchase an upgraded version of Visual Studio, or can I use another editor? Additionally would someone point me in the direction of a good tutorial outlining the basic use of resource files, and/or briefly explain the basics.

If resource files are not what I need, can you please point me in the direction of a method (if there is one) of doing this?

Thank you very much :),

-Nathaniel Sheller
why are you uncomfortable with the png files being accessible like that?
Ehh, just a preference I guess. If I were to release a commercial game I would like to know how to hide them :P.
You could simply write a small program to generate a const array of unsigned char that embeds the file into a C++ source. It's only recommendable for smallish files, though, as they'll be loaded to memory when the program runs.
The other alternative is do what everyone does: ZIP files with the extension changed, possibly combined with some obfuscation to not make it trivial to extract the files. Using non-standard compression algorithms also works.
Last edited on
What's wrong with Windows resources? This is what they are designed for.

Hope this helps.
Thank you very much guys :). Very helpful information. My problem with Windows resources too is that they are Windows specifically. If I wanted to port my code to another platform I would have to find an alternative method :).
There isn't any real alternative in Linux -- you supposedly just stick stuff in the proper directories. This has a lot to do with the design philosophy of Linux, alas. All hope isn't lost, though. Check out

On Mac OSX, you use application "bundles".

TL;DR = there is no portable way without using someone's framework, like

Hope this helps.
The best way of doing this would probably to have some level of encryption on the png files. You could write some simple encryption software--just enough so that the average user won't be able to decrypt it. Encrypt your png files and as you load them decrypt them in the program. Since your png files must be displayed on the screen, and for this to happen, the graphics card must have unencrypted access to the image files, you cannot make your png files completely secure from being ripped from your software and used elsewhere, but luckily there are copyright laws against doing this (in the US at least).
On Mac OSX, you use application "bundles".
yes, however as to not get your hopes up op, you can still access the files in bundles.
(Someone) can access the files no matter how you store them.

The idea to apply some simple encryption is a good one. However, there does not need to be a file on disk in order to be used by the graphics card.

When your application loads, your resource will be in memory. Access it enough to decrypt it to another piece of memory. Load the image (or texture or whatever your framework calls it) from the decrypted data in memory.

Hope this helps.
Topic archived. No new replies allowed.