Get Path of loaded ofImage

I am loading an image into ofImage. Is there a way to get the path of the loaded image?

Specifically, I am checking if it loaded, and if it didn’t I want to display the path that failed.

(And I know there are other ways to accomplish this, but I wanted to see if its possible to get the path from ofImage).

Thanks…

mike

I looked at the source code for ofImage::load on github:

(line 661)

It doesn’t look like the class saves the filename in any place; so the best way to accomplish what you want is probably something like this:

std::string filename = "path/to/file";

ofImage img;

if(!img.load(filename)) {
    display_file_path(filename);
}

Thanks. Yes, that is the workaround I could do, but I wanted to see if it was possible (it would definitely be useful).

Btw, for my specific use case, ofImage.load will actually give an error with the path if it cant load the image.

mike

You can always define a class which extends ofImage, something like ofImageWithFilename (not tested):

class ofImageWithFilename : public ofImage
{
public:
    bool specialLoadImage(const string & filename)
    {
        m_filename = filename;
        return this->loadImage(filename);
    }
private:
    string m_filename;
}