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

Author Topic: Checking the existence of an image?  (Read 1500 times)

0 Members and 1 Guest are viewing this topic.

The_Mezentine

  • Newbie
  • *
  • Posts: 16
    • View Profile
Checking the existence of an image?
« on: July 29, 2011, 05:44:42 am »
Is there any way to run a simple check on weather an image has been initialized/exists? I have a static image member as a class to share among all instances, and I want to only call image.create (or image.load) on the creation of the first object (obviously). There doesn't seem to be a method that would do what I want, and just trying "if(image)" and "if(!image == NULL)" don't work (two things I thought might)

I'm currently jury-rigging it with this, but it feels inelegant.

Code: [Select]

if(BrickImage.GetHeight() < 5){
BrickImage.Create(15, 80, sf::Color(100, 255, 255));
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Checking the existence of an image?
« Reply #1 on: July 29, 2011, 07:35:54 am »
There's no direct function to check if an image is empty or not, but you can easily make one:
Code: [Select]
bool IsEmpty(const sf::Image& image)
{
    return (image.GetWidth() == 0) || (image.GetHeight() == 0);
}
Laurent Gomila - SFML developer

The_Mezentine

  • Newbie
  • *
  • Posts: 16
    • View Profile
Checking the existence of an image?
« Reply #2 on: July 29, 2011, 05:44:06 pm »
Quote from: "Laurent"
There's no direct function to check if an image is empty or not, but you can easily make one:
Code: [Select]
bool IsEmpty(const sf::Image& image)
{
    return (image.GetWidth() == 0) || (image.GetHeight() == 0);
}

Excellent, thanks. I was considering that, but its nice to see it laid out like that.