How To Create A BinaryData Object?

Excuse me, Im a noob :smiley:

I wanna show a PNG image on the window.

but, I donā€™t know that how to create a BinaryData object. Like this:

// JUCER_RESOURCE: demoPng_png, 15290, "ā€¦/ā€¦/ā€¦/ā€¦/ā€¦/ā€¦/ā€¦/ā€¦/Users/jules/Desktop/DemoPNG.png"
static const unsigned char resource_RenderingTestComponent_demoPng_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,140,0,0,0,86,8,6,0,0,0,29,101,126,119,0,0,0,9,112,72,89,115,0,0,11,19,0,
0,11,19,1,0,154,156,24,0,0,0,4,103,65,77,65,0,0,177,142,124,251,81,147,0,0,0,32,99,72,82,77,0,0,122,37ā€¦

Please help me, Thx!!! :idea:

Do you mean that you donā€™t know how to turn a png into a binarydata file, or that you donā€™t know how to load the data as an imageā€¦?

Bothā€¦sorry for my bad :smiley:

You have to use the binarybuilder.
Go in juce/extras/binarybuilder
Compile it for your platform and use it!

[quote=ā€œmasshackerā€]You have to use the binarybuilder.
Go in juce/extras/binarybuilder
Compile it for your platform and use it![/quote]

Yeah! Thatā€™s what I need!!! Thank you~~!

or just use the old jucerā€¦(ā€”> add new resource)

Or use the new Introjucer - just add the resource file to your project, and the introjucer will automatically create a binarydata file for your project, and even add it to your header file, etc.

2 Likes

Iā€™m stuck here as well - how exactly does this work? I have a few GIFs and PNGs Iā€™d like to add to a project. How do I do this, exactly? Right now Iā€™m just reading their location from the hard drive manually, but for ease of cross-platform compatibility Iā€™d like to go the BinaryData route. Copying the GIFs into the BinaryData folder in my project in the IntroJucer seems to do nothing. Any ideas? :\

Just add them to your introjucer project, and itā€™ll automatically generate a BinaryData class containing them.

1 Like

Thatā€™s pretty nifty Jules

1 Like

Hi Jules, to bump this again - I just got the 1.53.98 JUCE build, and when I try to build the introjucer from this build it doesnā€™t display the behavior above. If I go to ā€œBinaryDataā€ and add files, all that happens is the files get added. There are two checkboxes for each entry - ā€œCompileā€ and ā€œAdd to Binary Resources.ā€ Checking either of these doesnā€™t seem to autogenerate a CPP file or anything like that.

Is there a new build of the Introjucer, perhaps, that isnā€™t in the 1.53.98 build? Iā€™m so confused over this, Iā€™ve been pulling my hair out over it for a few days now.

Thanksā€¦

[quote=ā€œBoozerā€]Hi Jules, to bump this again - I just got the 1.53.98 JUCE build, and when I try to build the introjucer from this build it doesnā€™t display the behavior above. If I go to ā€œBinaryDataā€ and add files, all that happens is the files get added. There are two checkboxes for each entry - ā€œCompileā€ and ā€œAdd to Binary Resources.ā€ Checking either of these doesnā€™t seem to autogenerate a CPP file or anything like that.

Is there a new build of the Introjucer, perhaps, that isnā€™t in the 1.53.98 build? Iā€™m so confused over this, Iā€™ve been pulling my hair out over it for a few days now.

Thanksā€¦[/quote]

This is Introjucer version 3.0.0, I should also say.

Thanks

And itā€™s on Mac OSX Snow Leopard too, if that means anything.

It works just fine - I use it every day! All the juce demoā€™s binary files are done that way.

You need to disable the ā€œcompileā€ option and tick the ā€œadd to binary resourcesā€ one. Itā€™ll magically create the binary cpp files and put them in the JuceLibraryCode folder.

BinaryData generates a string, but its not obvious what to do with theĀ (const char*)

You can do something like the following:

Ā  Ā  Ā  Ā Ā Image splash = ImageFileFormat::loadFrom(BinaryData::splashscreen_png, (size_t) BinaryData::splashscreen_pngSize);

What about memory? Its binaryData always in memory? How manage it?
I first look i think this bad solution, if you have many resources, or Iā€™m wrong and not understand correctly it ā€œmagicallyā€ creating resources? On Mac i see binData in memory on first call. What about other platforms and how free it?

As joelt and others wrote above:

It is compiled into the binary, so it is loaded when the application starts. And thatā€™s the whole point to embed binary data into the binary/application/executable so it cannot be replaced without reverse engineering.

You can load your binary data, images, icons etc. dynamically from normal files, you donā€™t need to use BinaryData, if you want it to be loaded later and manage it on your own.

Itā€™s what I need too!

You read julesā€™ post how it is done nowadays?

HTH

And how to get BinaryData if I donā€™t user projucer, but build my project with cmake in VSCode?