Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lelion

Pages: [1]
1
Graphics / Re: sf::Texture load from memory
« on: May 21, 2019, 01:34:00 am »
static const unsigned char embeddedImageData[] =
{
    /* content generated by one of the hundreds
        of programs that do it, or by your own small utility
       (doesn't take more than 10 lines of C++ code) */

};

texture.loadFromMemory(embeddedImageData, sizeof(embeddedImageData));

Example of code that generate such an array:

#include <fstream>
#include <iomanip>

int main(int argc, char** argv)
{
    std::ifstream in("image.png", std::ios_base::binary);
    std::ofstream out("header.hpp");

    out << "static const unsigned char embeddedImageData[] =" << std::endl;
    out << "{" << std::endl;
    do
    {
        out << "    ";
        for (int i = 0; (i < 20) && in; ++i)
            out << "0x" << std::hex << std::setw(2) << std::setfill('0') << in.get() << std::dec << ", ";
        out << std::endl;
    }
    while (in);
    out << "};" << std::endl;

    return 0;
}
 

Note that it can be more concise if you don't care about the pretty formatting.
(delete last 0xffffffff)

Merci beaucoup Laurent pour ce bou de code,  ca marche a merveille.

Pages: [1]
anything