Hi, i’m very new on JUCE (in fact, this is my first time), and not an c++ expert, i just clicked the “GUI” template on JUCE and began testing some options.
I saw people create a ImageComponent to add image, but i’m not sure that i want to create components for all images i want to add, so i tried to draw the image directly by the “paint” function, the code is like this:
As you can see, i’m just figuring things out in the “hello world” template.
The code compiles successfully, but the screen don’t draws my beautiful flower.
Should i use ImageComponent?
Maybe this code makes no sense, as i said, i’m kinda new in c++…
Kinda off topic, but, is there a way to create and image from a data vector?
I mean, i’m using this CImg and it creates and image object that i can save as PNG, BMP or JPG, but, if i use the line of code you just sent me i would have to first load into the resources, don’t?
Isn’t there a way to me to extract the data of “CImg” object and transform in “juce::Image” object? I think i can use the “setPixelColour” method of BitmapData… But the reference said i should “really know what i’m doing”.
You probably need to get more familiar with Projucer first.
Bring up the File Explorer in Projucer.
Right-click ‘Source’ and ‘Add new Group’
Name your group and move the folder to above ‘Source’ to make things clearer.
Right-click the new group and ‘Add Existing Files’ then select your PNG file.
This will add the png to the project. This will automatically go in you project as a memory resource as a part of BinaryData.h.
This is where the above code can access the block of data with getFromMemory access.
You can add any file to the Projucer this way, including text, waveform files etc.
I’m sorry but I’m not familiar with CImg and ‘data vector’ objects.
Don’t worry, you already helped a lot and thank you very much for that!
But if you are curious:
CImg is a very simple header for image processing.
You open or create an image with an object called “CImg”.
This object have a method to save in bmp, png and etc… So i was thinking about saving the files in the program folder and use JUCE to call it, but if there was a way to get directly from the CImg memory and transfer to the juce::Image it would be way simpler, but nvm about that, i’ll figure it out by time. Probably using pointers and stuff…
The function ImageCache::getFromMemory() can load from any valid memory location. It just takes a location and a size as its parameters. So, if your CImg class has the ability to write the image as a PNG, but in memory instead of to a physical file, then you can use that memory location. But since we have no idea what the interface or abilities of a CImg object are, we can’t say if it provides a way to access its image data in a format that juce::Image can handle. Not sure why you want to use an external library for image handling, exactly, or if you need to do so in the same application, or separate apps, so I can’t say if writing to a file using your CImg class and at some point later in time loading it into a (different?) JUCE app is what you need or not.
Don’t worry, if i could open directly from CImg memory would just be a bonus, at least i can open the PNG i save from it by JUCE and that is good enough.
I’ll check out this getFromMemory method.
Not sure why you want to use an external library for image handling
Because CImg have some methods alike “photoshop” if you know what i mean, but CImg is more about manipulating image, if i had to make a GUI with it, i would have to make it almost from scratch, so, using JUCE for the GUI to manipulate the methods i use in CImg would be very cool.
But don’t worry about that, what i wanted was to open the file and it was just this bmp issue.
I mean, i’m saving from CImg and opening with JUCE, but i wanted to not need to save the image and display it one JUCE, but don’t worry about that, it is just a small issue that don’t matter much, the main problem i had was opening that image and it was solved, so, thanks everybody!