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

Author Topic: Program Unable to load images  (Read 1659 times)

0 Members and 1 Guest are viewing this topic.

dissimulation

  • Newbie
  • *
  • Posts: 6
    • View Profile
Program Unable to load images
« on: May 07, 2012, 10:46:41 pm »
My program is unable to load my images, I've tried switching the images between various types (.jpg, .bmp, .png). Also, I have tried putting in the absolute directory to load the image.

here is some code of where I have my error

Code: [Select]
sf::Image PlayerImage;
PlayerImage.LoadFromFile("C:\Users\Kevin\Documents\Visual Studio 2008\Projects\Project1\R_Arena\Release\PlayerImage.bmp");

I was also having trouble loading fonts earlier on before I gave up and moved on.

Sorry if this is a newbie question or if the answer is somewhere else on the forum, but I wasn't able to find a solution.

OutlawLee

  • Jr. Member
  • **
  • Posts: 50
  • This is my personal text. Dont read it.
    • View Profile
    • Email
Re: Program Unable to load images
« Reply #1 on: May 07, 2012, 11:53:26 pm »
Code: [Select]
sf::Image PlayerImage;
PlayerImage.LoadFromFile("PlayerImage.bmp");

You dont have to put the full path. And im not sure if the release works if you put there files since it didnt work for me.

But go into: R_Arena\Debug, put in there the picture beside the .exe file and it will load 100%.

P.S.

That is just for loading the image, and not for displaying it.

dissimulation

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Program Unable to load images
« Reply #2 on: May 08, 2012, 12:15:11 am »
I've tried both in release mode and in debug mode, the picture is in both folders next to the EXE. Also, I know this isn't for displaying it, the game gives the error "unable to load image" when i give this command.


Hmm, I tried taking out the full file name while using .bmp Sorry for wasting your time.

**Solved**
« Last Edit: May 08, 2012, 01:02:12 am by dissimulation »

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Program Unable to load images
« Reply #3 on: May 08, 2012, 08:13:13 am »
What compiler are you using, and do you have warnings enabled? At least GCC gives me warnings about unknown escape sequences..

If you write down your path like "C:\Foobar", the compiler tries to escape "\F", which is not a valid escape sequence and afair (not sure what the standard says) it will be dropped from the string. To actually get a "\", you write "\\".

Using relative paths however is much better, and using "/" as path delimiter also (it works on Windows, Linux and OSX).