I wanted to incorporate an image into my component. (Eventually I want to play an animated GIF, but baby steps first!). So I peruse the documentation, and this is the best I came up with:
first create a default constructed Image gifImage;
in the private:
section as this will store an invalid Image for us on the stack, ready for us when we load it up with something:
Then we need a File object to store the path to the file. Initially I tried File file{“test.gif”} And even though the documentation says: "If the path supplied is a relative path, it is taken to be relative to the current working directory"
It gives me an assertion error. The JUCE forums revealed this bit of code that seems to work (without assertion failure):
File file = File::getCurrentWorkingDirectory().getChildFile("test.gif");
Side question: What is File::
doing? Is it constructing a disposable object (with no name) so that we can access it’s getCurrentWorkingDirectory()
function one time only? rather than having to do this:
File file;
File file2;
file2 = file.getWorkingDirectory();
file3 = file2.getChildFile("test.gif");
Also can anyone name what is happening when a function has a .
to another function, so I can learn more about this syntax?
Anyway, so now I have a file loaded into file
, I need to make an InputStream because that’s what GIFImageFormat is going to want to return an Image. So…
FileInputStream fileInputStream(file);
No errors yet.
Now it’s only when I’m on the last stage that it results in the assertion error: JUCE Assertion failure in juce_FileInputStream.cpp:46
:
GIFImageFormat gifImageFormat;
gifImage = gifImageFormat.decodeImage(fileInputStream);
// Hooray we have loaded a file into gifImage!
Side question: shouldn’t I be able to do something like this, just as before?
gifImage = GIFImageFormat::decodeImage(fileInputStream);
So this is where I am, unable to load up an image from file
Sorry for the tedious, perhaps constant, and uninteresting questions I keep asking. I really am trying to figure this out on my own, and have dedicated about two hours to this problem already.
Kind of Side Question: If anyone has any recommendation for what skill I am lacking, outside of this particular problem, that is going to help me with future such problems (i.e. reading / interpreting documentation etc.) - what fundamental programming skill I am missing and where I can go to get better, then please say!
As always, a million thanks