c++ - How to embed a file into an executable? -
I have written a small demo executable in C ++ which can only be loaded before running on a 5kb PNG image Due to this one file I used for a pixel text, I would have to give a zip archive instead of just an executable file, which produces enough friction between download and 'play', which I believe Some will stop it from doing this.
My question is that is there any way to embed a PNG file (and actually any other file) in the executable or source code, so that it is a file, and Can executable use it? I have the ability to parse PNG as a byte stream, so there is no need to convert it to pixel data. Thanks in advance thanks! (There are other questions with a similar title for this, but they and their answers seem to be more specific and are not very useful) Edit : Compiler View C ++ 2010 and it's on Windows (though I would like to avoid windows specific utilities for it)) edit2 : Alpha's answer looked like the most portable method , So I quickly got a PNG file from a TXT or head And works in parsing the file which can be read as the If you want to see the code, but still if you think that they are better than this method then accept the other answers: Last Editing : What I mentioned to Alpha, what I need, thank you! Defining a functional function such as Then you just have to write a small assistant program which reads PNG file as binary and creates C ++ Curtis Braces Anilizer text. Edit : @Woodland has commented on this question, in which there is such a small supporting program ... Of course, for a Windows-specific program Instead, use Simple Windows Resource Planning. Cheers & amp; Hth., unsigned char array. It appears that this form is in the PNG file itself, but does not accept my PNG loader array Will do When loading it from memory, the PNG parser takes a
(zero * buffer, size_ty length) , if this is the case.
Zero compilation image PNGtoBinary (Char * filename, char * output) {FILE * file = fopen (filename, "rb"); File * out = FOPN (output, "W"); Unsigned char buffer [32]; Size_t count; Fprintf (Outside, "#pragma once \ n \ nStateless unsigned letter TEXT_PNG_BYTES [] = {"); While (! FIFF) {count = fread (buffer, 1, 32, file); For (int n = 0; n & lt; count; + + n) {fprintf (outside, "0x% 02X,", buffer [n]); }; }; Fprintf (outside, "};"); Fclose (file); Fclose (outside); };
typedef unsigned Four bytes; Byte Constance * pngFileData () {Fixed Byte Conte Data = {// byte data is generated by an auxiliary program. }; Return data; }
Comments
Post a Comment