How To Create A BinaryData Object?


#1

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:


#2

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…?


#3

Both…sorry for my bad :smiley:


#4

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


#5

[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~~!


#6

or just use the old jucer…(—> add new resource)


#7

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.


#8

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? :\


#9

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


#10

That’s pretty nifty Jules


#11

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…


#12

[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


#13

And it’s on Mac OSX Snow Leopard too, if that means anything.


#14

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.


#15

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);


#16

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?


#17

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.


#18

It’s what I need too!


#19

You read jules’ post how it is done nowadays?


HTH