JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Classes | Static Public Member Functions | Friends | List of all members
juce::ImageCache Class Reference

A global cache of images that have been loaded from files or memory. More...

#include "juce_ImageCache.h"

Classes

struct  Pimpl
 

Static Public Member Functions

static Image getFromFile (const File &file)
 Loads an image from a file, (or just returns the image if it's already cached).
 
static Image getFromMemory (const void *imageData, int dataSize)
 Loads an image from an in-memory image file, (or just returns the image if it's already cached).
 
static Image getFromHashCode (int64 hashCode)
 Checks the cache for an image with a particular hashcode.
 
static void addImageToCache (const Image &image, int64 hashCode)
 Adds an image to the cache with a user-defined hash-code.
 
static void setCacheTimeout (int millisecs)
 Changes the amount of time before an unused image will be removed from the cache.
 
static void releaseUnusedImages ()
 Releases any images in the cache that aren't being referenced by active Image objects.
 

Friends

struct Pimpl
 

Detailed Description

A global cache of images that have been loaded from files or memory.

If you're loading an image and may need to use the image in more than one place, this is used to allow the same image to be shared rather than loading multiple copies into memory.

Another advantage is that after images are released, they will be kept in memory for a few seconds before it is actually deleted, so if you're repeatedly loading/deleting the same image, it'll reduce the chances of having to reload it each time.

See also
Image, ImageFileFormat

@tags{Graphics}

Definition at line 46 of file juce_ImageCache.h.

Member Function Documentation

◆ addImageToCache()

void juce::ImageCache::addImageToCache ( const Image image,
int64  hashCode 
)
static

Adds an image to the cache with a user-defined hash-code.

The image passed-in will be referenced (not copied) by the cache, so it's probably a good idea not to draw into it after adding it, otherwise this will affect all instances of it that may be in use.

Parameters
imagethe image to add
hashCodethe hash-code to associate with it
See also
getFromHashCode

Definition at line 130 of file juce_ImageCache.cpp.

◆ getFromFile()

Image juce::ImageCache::getFromFile ( const File file)
static

Loads an image from a file, (or just returns the image if it's already cached).

If the cache already contains an image that was loaded from this file, that image will be returned. Otherwise, this method will try to load the file, add it to the cache, and return it.

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

Parameters
filethe file to try to load
Returns
the image, or null if it there was an error loading it
See also
getFromMemory, getFromCache, ImageFileFormat::loadFrom

Definition at line 135 of file juce_ImageCache.cpp.

◆ getFromHashCode()

Image juce::ImageCache::getFromHashCode ( int64  hashCode)
static

Checks the cache for an image with a particular hashcode.

If there's an image in the cache with this hashcode, it will be returned, otherwise it will return an invalid image.

Parameters
hashCodethe hash code that was associated with the image by addImageToCache()
See also
addImageToCache

Definition at line 122 of file juce_ImageCache.cpp.

◆ getFromMemory()

Image juce::ImageCache::getFromMemory ( const void imageData,
int  dataSize 
)
static

Loads an image from an in-memory image file, (or just returns the image if it's already cached).

If the cache already contains an image that was loaded from this block of memory, that image will be returned. Otherwise, this method will try to load the file, add it to the cache, and return it.

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

Parameters
imageDatathe block of memory containing the image data
dataSizethe data size in bytes
Returns
the image, or an invalid image if it there was an error loading it
See also
getFromMemory, getFromCache, ImageFileFormat::loadFrom

Definition at line 149 of file juce_ImageCache.cpp.

◆ releaseUnusedImages()

void juce::ImageCache::releaseUnusedImages ( )
static

Releases any images in the cache that aren't being referenced by active Image objects.

Definition at line 169 of file juce_ImageCache.cpp.

◆ setCacheTimeout()

void juce::ImageCache::setCacheTimeout ( int  millisecs)
static

Changes the amount of time before an unused image will be removed from the cache.

By default this is about 5 seconds.

Definition at line 163 of file juce_ImageCache.cpp.

Friends And Related Symbol Documentation

◆ Pimpl

friend struct Pimpl
friend

Definition at line 119 of file juce_ImageCache.h.


The documentation for this class was generated from the following files: