This question has already been answered:
Hello! Tell me, can this be done only through resources or something else? If how else can you give an example?
This question has already been answered:
Hello! Tell me, can this be done only through resources or something else? If how else can you give an example?
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
I will try to explain in detail the introduction of an external file in the data. So, part 1. We write a program that reads a file in binary (not text mode !!), and writes each byte as an element of an array. See, for example, this code .
Part 2. Apply this program to an external file, we get a file with a description of the array. Type unsigned char img[] = { 0x02, 0x15, ... Even better, add immediately a second variable of type int img_len = ...
Part 3. Paste this file into the project. Where necessary - refer to this array; for example, to write it back to the file -
FILE * f = fopen("out","wb"); if (f) { fwrite(f,img,1,img_len); fclose(f); } Like that.
There is an old-fashioned way. Having a file of the image, generate on it the code of the declaration of the array of the form
const char a[] = { ... }; where ... is data from a file, of course, in the form of correctly written constants. Get an array identical to the contents of the image file. The type of the array may be different, depending on which one is more convenient to use.
Then just include this file in the project, use the array as external. Alternatively, it is possible to place in the array not the entire contents of the file, for example, without a header, etc. depending on the image format.
Source: https://ru.stackoverflow.com/questions/575818/
All Articles