title: Loading image from memory
body: <p>According to the <a href="http://www.sfml-dev.org/documentation/2.1/classsf_1_1Texture.php" rel="nofollow">documentation</a>, one can load an <code>sf::Texture</code> three different ways: from file, from stream, from memory. I think I need the latter, but I'm not even sure about that. And if I do, I can't figure out how to use it.</p>
  
  <p>I have a method, which, given an url to work with, needs to return an <code>sf::Sprite</code>. I'm successfully downloading the binary data, and storing it in a string (since <code>Http::Response::getBody()</code> returns that). I know for a fact, that this is the right data, because if I write and save it to a file, I can view the image. I don't want a file however, I just need the image displayed.</p>
  
  <p>Here is the function:</p>
  
  <pre><code>sf::Sprite Downloader::GetPicture(const std::string &amp;url)
  {
      sf::Http http;
      std::string host = url.substr(0, url.find("net/")+4 );
      std::string uri = url.substr(url.find("net/")+4, url.size());
      http.setHost(host);
      request.setUri(uri);
      response = http.sendRequest(request);
      std::string data = response.getBody();
  
      //THIS IS WRONG
      sf::Texture texture;    
      texture.loadFromMemory((void*)data, sizeof(data));
      return sf::Sprite(texture);
  
      /* THIS WORKS, BUT I DON'T WANT TO SAVE, REOPEN, THEN DELETE AT THE END
      std::ofstream fileout("test.jpg", std::ios::binary);
      fileout &lt;&lt; data;
      fileout.close();
      */
  }
  </code></pre>
  
  <p>Here is <code>loadFromMemory</code>'s <a href="http://www.sfml-dev.org/documentation/2.1/classsf_1_1Texture.php#a2c4adb19dd4cbee0a588eeb85e52a249" rel="nofollow">signature</a> for the lazy (the <code>void*</code> confuses me, that's probably the problem).</p>
  
  <p>Also, this might be a completely wrong way to do it; maybe extending <code>sf::InputStream</code>, and using <code>loadFromStream</code>?</p>
  
  <p>The problem is, returned <code>sf::Sprite</code> has 0×0 dimension and 0 size, that's how I know it's wrong.</p>