Insert image into code without using resource section or external images

I am looking for a way to embed an image in a library (Windows only). I don’t want to go in the "traditional" way to put it in resources (due to special circumstances, because of which it is not so convenient to deal with a resource descriptor.

Ideally, it would be something like xpm files: a β€œtextual” representation of an image that fits in an ac array, and that some code is converted to a bitmap image in memory, which can then be loaded into HIMAGE or HICON in some way. Images that I want to implement are 32-bit bitmaps (BMPs). Any ideas? I use MFC, so the MFC library will be fine, but of course I can use a library that also does not use MFC. Thank.

+1
c ++ visual-c ++ mfc
Oct 22 '08 at 12:06
source share
3 answers

Google for the bin2c utility (something like http://stud3.tuwien.ac.at/~e0025274/bin2c/bin2c.c ). It takes a binary representation of the file and produces the original C file, which includes an array of bytes initialized with this data.

Just merge the file and you have an image sitting in a piece of memory.

Using this type of tool is really common on embedded systems, where things like "resources" and even files may be missing.

+6
Oct 22 '08 at 13:09
source share

Gimp can export C files. I think this would be the easiest way to do this.

+2
Oct 22 '08 at 14:02
source share

The Hexy open source application is specifically designed for this. It works on windows and linux. https://github.com/tristan2468/Hexy

+1
May 16 '11 at 15:27
source share



All Articles