Appropriate File path

Sorry for stupid question,
but I’ve just spent 2 hours to find the solution which seems to be something trivial.

I need to include on my plugin window GUI the picture, for example logo. So I am not sure how it is with VST and other formats, but I suppose for AU plugins my picture (myPicture.png) should be included in myPlugin.component package. That no matter where and on which computer (Mac) I launch my plugin, the logo should appear.

So how to make xCode copy the file to myPlugin.component package and what should be the path of that File in the code to get that file?

I tried that:
File myFile = File::getSpecialLocation(File::currentApplicationFile).getFullPathName().getChildFile ("myFile.png");

But I get error. I also tried many more configurations, but nothing works for me. Please help me :slight_smile:

OK, I finally found out that works:

const String pathToFile = File::getSpecialLocation(File::currentApplicationFile).getChildFile ("myFile.png").getFullPathName();
File pajLogoFile = pathToFile ;

But then I need to copy myFile.png to component package. Can I do that XCode do that automatically?

I’d highly recommend adding the icon as a binary resource, and then the image is saved inside the actual plugin binary file.

To do this add the image to the File Explorer in the Projucer, just like you would with source code file. When you re save the jucer document it should add the data to BinaryData.h/cpp and you can access the file directly in the code using myIcon_png and myIcon_pngSize. To load it as an image there’s a handy function in the ImageCache class: ImageCache::getFromMemory, which you can use like this:

Image iconImage = ImageCache::getFromMemory (myIcon_png, myIcon_pngSize);

Also in your previous example you were converting a File to a String and back again. The correct to do it would be like this:

File pajLogoFile = File::getSpecialLocation (File::currentApplicationFile).getChildFile ("myFile.png");
1 Like

But then I need to copy myFile.png to component package. Can I do that XCode do that automatically?

Just mark the .png as an “Xcode resource” in the projucer.

But I agree with @alibarker1. It’s easier to deal with images as binary resources across platforms, rather than as files tucked away in some directory.

1 Like

Wow, thank you so much!
I never knew that was an option…
Maybe there could be a tutorial on loading Images from files and into Components? As a newbie it was a real struggle getting my first ImageButton working…