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

Author Topic: sf::Image.loadFromMemory example?  (Read 3520 times)

0 Members and 1 Guest are viewing this topic.

gameus

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
sf::Image.loadFromMemory example?
« on: May 04, 2013, 04:42:15 am »
After googling on how to embed images into an SFML project, Laurent posted a suggestion about putting the file into the header and using loadFromMemory to create the image. I've been trying to figure out how to do this and I'm not quite sure how, I was wondering if someone could post an example on how to use this method properly? It'd be much appreciated. Thanks in advance!

This is just something I want to experiment with and I'm just trying to learn from it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Image.loadFromMemory example?
« Reply #1 on: May 04, 2013, 08:12:24 am »
You first need to find (or write) a program which converts a file to a C header. You'll get something like this:

const char my_file[] =
{
    ... lots of digits pairs ...
}

Then you load it this way:

image.loadFromMemory(my_file, sizeof(my_file));
Laurent Gomila - SFML developer

gameus

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: sf::Image.loadFromMemory example?
« Reply #2 on: May 04, 2013, 09:18:31 am »
Ah okay, thanks so much! I was just confused on what had to be in the memory I guess. Works perfectly now, thanks so much!