Reimport an image after it changes

Is there no way to reimport an image after you change it in an external editor, other than restarting BOTH projucer and IDE? Ive seen this topic (File/ImageCache change detection), but it doesnt explain why isnt there at least a manual “Reimport” option in the projucer.

Indeed, an invalidate method for cached items might be useful.
However, you can avoid that, if you follow the hint in the docs for ImageCache::getFromMemory():

Remember that the image returned is shared, so drawing into it might affect other things that are using it! If you want to draw on it, first call Image::duplicateIfShared()


Thanks for reply! Can you please give an example how that can be used? Cause i dont really get it how it helps in this case.

Sure, when you retrieve an Image via the ImageCache, you probably did something like:

Image myImage = ImageCache::getFromMemory (BinaryData::myimage_png, BinaryData::myimage_pngSize);
Graphics g (myImage);
g.fill (Colours::blue); // myImage is shared with the cached one, so every time you fetch from ImageCache, the blue image is returned


Image myImage = ImageCache::getFromMemory (BinaryData::myimage_png, BinaryData::myimage_pngSize);
myImage.duplicateIfShared(); // makes sure that this image doesn't share the underlying data
Graphics g (myImage);
g.fill (Colours::blue); // no other Image is painted on

So probably every time when you start drawing on an Image, call duplicateIfShared() (not every time you read from, otherwise there is no point in caching the Image in the first place)

Hm, i dont think you get it. The image doesnt change while the program is running. My problem is that the binary data isnt updated, after i change the image, and neither does the image preview in the projucer. So when i try to build it with changed image, it says that there is no changes and theres no need to build. That is unless i restart both projucer and my IDE, then it updates the binary data, and i can build with updated image.

Ah, sorry, yes I didn’t get it.

That is because there is a tool, that converts the Image from disk into a memory block, that is found in BinaryData and will be compiled in.

If you hit “Save Project” in Projucer’s File menu, the BinaryData array should be recreated. So your IDE should realise then, that a source file has changed.

Hope that answer is better :wink:

1 Like

Thanks! That works, however it has an unfortunate drawback of needing to recompile some builtin modules after that. Still better and faster than restarting it.