hello
i was working on sf::texture to load image from memory by encoding the source image in base46 and decode it back to be able to load it in sf::texture. i have create encoder.cpp and decoder.cpp to accomplish this as shown in these files
the encoder is simply encode the given image and create .pin file as binary
here encoder.cpp :
https://gist.github.com/MORTAL2000/05f5b100166203ed3cc7the file being created like this. sfml-logo-small.pin
content :
https://gist.github.com/MORTAL2000/4206d168740a8af7b295the decoder is convert sfml-logo-small.pin to be readable in sf::Texture.
here decoder.cpp :
https://gist.github.com/MORTAL2000/af02e3ac4212924a30e7source image is found here:
if i loaded the encoded image "sfml-logo-small.pin", which is simply a string, from file, it works fine but if i copy and paste it into std::string object in encoder.cpp to read it directly instead of read it from file, i keep getting error says
corrupt PNG. how to fix this.
P.S: i have to split the std::string object into two string like this:
static const std::string data0 = "copy and paste from sfml-logo-small.pin ... very long encoded string";
static const std::string data1 = "copy and paste from sfml-logo-small.pin ... very long encoded string";
otherwise the VC14 will complain about it as
string is too bigand use it like this:
std::string decoded = base64_decode({ data0 + data1 });
sf::Texture texture;
if (!texture.loadFromMemory(decoded.c_str(), decoded.length()))
{
return 1;
}