Interface BitmapPool
-
- All Known Implementing Classes:
BitmapPoolAdapter,LruBitmapPool
public interface BitmapPoolAn interface for a pool that allows users to reuseBitmapobjects.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclearMemory()Removes allBitmaps from the pool.android.graphics.Bitmapget(int width, int height, android.graphics.Bitmap.Config config)Returns aBitmapof exactly the given width, height, and configuration, and containing only transparent pixels.android.graphics.BitmapgetDirty(int width, int height, android.graphics.Bitmap.Config config)Identical toget(int, int, android.graphics.Bitmap.Config)except that any returnedBitmapmay not have been erased and may contain random data.longgetMaxSize()Returns the current maximum size of the pool in bytes.voidput(android.graphics.Bitmap bitmap)Adds the givenBitmapif it is eligible to be re-used and the pool can fit it, or callsBitmap.recycle()on the Bitmap and discards it.voidsetSizeMultiplier(float sizeMultiplier)Multiplies the initial size of the pool by the given multiplier to dynamically and synchronously allow users to adjust the size of the pool.voidtrimMemory(int level)Reduces the size of the cache by evicting items based on the given level.
-
-
-
Method Detail
-
getMaxSize
long getMaxSize()
Returns the current maximum size of the pool in bytes.
-
setSizeMultiplier
void setSizeMultiplier(float sizeMultiplier)
Multiplies the initial size of the pool by the given multiplier to dynamically and synchronously allow users to adjust the size of the pool.If the current total size of the pool is larger than the max size after the given multiplier is applied,
Bitmaps should be evicted until the pool is smaller than the new max size.- Parameters:
sizeMultiplier- The size multiplier to apply between 0 and 1.
-
put
void put(android.graphics.Bitmap bitmap)
Adds the givenBitmapif it is eligible to be re-used and the pool can fit it, or callsBitmap.recycle()on the Bitmap and discards it.Callers must not continue to use the Bitmap after calling this method.
- Parameters:
bitmap- TheBitmapto attempt to add.- See Also:
Bitmap.isMutable(),Bitmap.recycle()
-
get
@NonNull android.graphics.Bitmap get(int width, int height, android.graphics.Bitmap.Config config)Returns aBitmapof exactly the given width, height, and configuration, and containing only transparent pixels.If no Bitmap with the requested attributes is present in the pool, a new one will be allocated.
Because this method erases all pixels in the
Bitmap, this method is slightly slower thangetDirty(int, int, android.graphics.Bitmap.Config). If theBitmapis being obtained to be used inBitmapFactoryor in any other case where every pixel in theBitmapwill always be overwritten or cleared,getDirty(int, int, android.graphics.Bitmap.Config)will be faster. When in doubt, use this method to ensure correctness.Implementations can should clear out every returned Bitmap using the following:bitmap.eraseColor(Color.TRANSPARENT);- Parameters:
width- The width in pixels of the desiredBitmap.height- The height in pixels of the desiredBitmap.config- TheBitmap.Configof the desiredBitmap.- See Also:
getDirty(int, int, android.graphics.Bitmap.Config)
-
getDirty
@NonNull android.graphics.Bitmap getDirty(int width, int height, android.graphics.Bitmap.Config config)Identical toget(int, int, android.graphics.Bitmap.Config)except that any returnedBitmapmay not have been erased and may contain random data.If no Bitmap with the requested attributes is present in the pool, a new one will be allocated.
Although this method is slightly more efficient than
get(int, int, android.graphics.Bitmap.Config)it should be used with caution and only when the caller is sure that they are going to erase theBitmapentirely before writing new data to it.- Parameters:
width- The width in pixels of the desiredBitmap.height- The height in pixels of the desiredBitmap.config- TheBitmap.Configof the desiredBitmap.- Returns:
- A
Bitmapwith exactly the given width, height, and config potentially containing random image data. - See Also:
get(int, int, android.graphics.Bitmap.Config)
-
clearMemory
void clearMemory()
Removes allBitmaps from the pool.
-
trimMemory
void trimMemory(int level)
Reduces the size of the cache by evicting items based on the given level.- Parameters:
level- The level fromComponentCallbacks2to use to determine how manyBitmaps to evict.- See Also:
ComponentCallbacks2
-
-