SFML community forums

Help => Graphics => Topic started by: The_Mezentine on July 29, 2011, 05:44:42 am

Title: Checking the existence of an image?
Post by: The_Mezentine 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));
}
Title: Checking the existence of an image?
Post by: Laurent 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);
}
Title: Checking the existence of an image?
Post by: The_Mezentine 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.