Load an image and draw it, but how?


I want to load an image and draw it. The 'Graphic"-instance from the paint method has a method to draw an image, but how does it work? Could someone give me a short example for loading an image (for example with the path “…/assets/image.png”) and draw it? I don´t want to use the Introjucer and i really want to use the drawImage method, because I want to create an own rotary slider consisting of single images (like an animation).

void ShaperAudioProcessorEditor::paint (Graphics& g)
	g.drawImage( ??? );

Greetz from Germany

Have a look at the ImageCache class (http://rawmaterialsoftware.com/juce/api/classImageCache.html#acc266a65cf61dd0a2f68e68840b4a5c4), use the getFromFile method to obtain a Image() boject to draw.

The `File’ object doesnt like relative paths. But you can build one from a special location (eg user documents) or an absolute path.

Once you’ve got this,

File f = ....; Image img = ImageFileFormat::loadFrom(f);
Then later in `paint’

g.drawImageAt(img, x, y);

1 Like