public final class EpicBitmapRenderer
extends java.lang.Object
Decode and render Bitmaps the epic and easy way, creating faster Android apps without extra effort.
This Android Bitmap decoder library follows the Google conventions for displaying bitmaps efficiently (see Google guide for more info), offering these features:
Bitmap
objects from different sources out of UI thread,
ensuring that your app runs smoothly.
OutOfMemoryError
EpicBitmapCache
. If an image
is previously rendered, next time it will be extracted from cache if available, and it will be used instead of re-rendering Bitmap from source again. This entire
process is automatic, as render methods handle cache themselves, and saves a lot of memory consumption from heavy processes like rendering images from disk or internet.
Modifier and Type | Method and Description |
---|---|
static int |
calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
Calculates downsample rate, if needed, for an image depending of width and height it should fit on.
|
static android.graphics.Bitmap |
decodeBitmapFromFile(java.lang.String path)
Decodes a
Bitmap object from a given file, at its original dimensions. |
static android.graphics.Bitmap |
decodeBitmapFromFile(java.lang.String path,
int inSampleSize)
Decodes a sampled
Bitmap object from a given file, using the inSampleSize specified. |
static android.graphics.Bitmap |
decodeBitmapFromFile(java.lang.String path,
int reqWidth,
int reqHeight)
Decodes a
Bitmap object from a given file, using the specified measures to calculate image downsample if needed. |
static void |
decodeBitmapFromFile(java.lang.String path,
int reqWidth,
int reqHeight,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled
Bitmap object from a given file asynchronously, using the specified measures to calculate image downsample if needed. |
static void |
decodeBitmapFromFile(java.lang.String path,
int inSampleSize,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled
Bitmap object from a given file asynchronously, using the inSampleSize specified. |
static void |
decodeBitmapFromFile(java.lang.String path,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a
Bitmap object from a given file asynchronously, at its original dimensions. |
static android.graphics.Bitmap |
decodeBitmapFromResource(android.content.res.Resources res,
int resId)
Decodes a
Bitmap object from a given app resource, at its original dimensions. |
static android.graphics.Bitmap |
decodeBitmapFromResource(android.content.res.Resources res,
int resId,
int inSampleSize)
Decodes a sampled
Bitmap object from a given app resource, using the inSampleSize specified. |
static android.graphics.Bitmap |
decodeBitmapFromResource(android.content.res.Resources res,
int resId,
int reqWidth,
int reqHeight)
Decodes a sampled
Bitmap object from a given app resource, using the specified measures to calculate image downsample if needed. |
static void |
decodeBitmapFromResource(android.content.res.Resources res,
int resId,
int reqWidth,
int reqHeight,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled
Bitmap object from a given app resource asynchronously, using the specified measures to calculate image downsample if needed. |
static void |
decodeBitmapFromResource(android.content.res.Resources res,
int resId,
int inSampleSize,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled
Bitmap object from a given app resource asynchronously, using the inSampleSize specified. |
static void |
decodeBitmapFromResource(android.content.res.Resources res,
int resId,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a
Bitmap object from a given app resource asynchronously, at its original dimensions. |
static void |
decodeBitmapFromUrl(java.lang.String url,
int reqWidth,
int reqHeight,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled
Bitmap object from a given url, using the specified measures to calculate image downsample if needed. |
static void |
decodeBitmapFromUrl(java.lang.String url,
int inSampleSize,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled
Bitmap object from a given url, using the inSampleSize specified. |
static void |
decodeBitmapFromUrl(java.lang.String url,
OnBitmapRendered onBitmapRendered,
OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a
Bitmap object from a given url, at its original dimensions. |
static EpicBitmapCache |
getCache()
Gets the instance of the current
EpicBitmapCache object being used as cache. |
static void |
initDiskCache(android.content.Context context)
Initializes disk caches.
|
static void |
setCache(EpicBitmapCache epicBitmapCache)
Sets
EpicBitmapCache object to use as cache. |
public static EpicBitmapCache getCache()
EpicBitmapCache
object being used as cache.public static void setCache(EpicBitmapCache epicBitmapCache)
EpicBitmapCache
object to use as cache.epicBitmapCache
- Cache to use by rendererpublic static android.graphics.Bitmap decodeBitmapFromResource(android.content.res.Resources res, int resId, int reqWidth, int reqHeight)
Decodes a sampled Bitmap
object from a given app resource, using the specified measures to calculate image downsample if needed.
Downsample rate is auto-increased if bitmap rendering causes an OutOfMemoryError
.
Important Note: This method is synchronous and can cause UI Thread to freeze,
use decodeBitmapFromResource(Resources, int, int, int, OnBitmapRendered, OnBitmapRenderFailed)
instead for an asynchronous solution.
res
- Resources package. You can get default resources package using ContextThemeWrapper.getResources()
inside an activity or Context.getResources()
outside if a Context
is available.resId
- App resource id. Could be either the pure integer value, or the Android resource name (R.drawable.img_name).reqWidth
- Required width of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.reqHeight
- Required height of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.Bitmap
object, ready to use on any View or code.public static android.graphics.Bitmap decodeBitmapFromResource(android.content.res.Resources res, int resId, int inSampleSize)
Decodes a sampled Bitmap
object from a given app resource, using the inSampleSize specified.
Important Note: This method is synchronous and can cause UI Thread to freeze, use
decodeBitmapFromResource(Resources, int, int, OnBitmapRendered, OnBitmapRenderFailed)
instead for an asynchronous solution.
res
- Resources package. You can get default resources package using ContextThemeWrapper.getResources()
inside an activity or Context.getResources()
outside if a Context
is available.resId
- App resource id. Could be either the pure integer value, or the Android resource name (R.drawable.img_name).inSampleSize
- Determines how many times image resolution is divided to lower memory usage. Image aspect ratio is not affected by this parameter, just its resolution / quality is lowered.Bitmap
object, ready to use on any View or code.public static android.graphics.Bitmap decodeBitmapFromResource(android.content.res.Resources res, int resId)
Decodes a Bitmap
object from a given app resource, at its original dimensions.
Important Note: This method is synchronous and can cause UI Thread to freeze,
use decodeBitmapFromResource(Resources, int, OnBitmapRendered, OnBitmapRenderFailed)
instead for an asynchronous solution.
res
- Resources package. You can get default resources package using ContextThemeWrapper.getResources()
inside an activity or Context.getResources()
outside if a Context
is available.resId
- App resource id. Could be either the pure integer value, or the Android resource name (R.drawable.img_name).Bitmap
object, ready to use on any View or code.public static android.graphics.Bitmap decodeBitmapFromFile(java.lang.String path, int reqWidth, int reqHeight)
Decodes a Bitmap
object from a given file, using the specified measures to calculate image downsample if needed.
Downsample rate is auto-increased if bitmap rendering causes an OutOfMemoryError
.
Important Note: This method is synchronous and can cause UI Thread to freeze, use decodeBitmapFromFile(String, int, int, OnBitmapRendered, OnBitmapRenderFailed)
instead for an asynchronous solution.
path
- Physical path of File in the device storage.reqWidth
- Required width of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.reqHeight
- Required height of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.Bitmap
object, ready to use on any View or code.public static android.graphics.Bitmap decodeBitmapFromFile(java.lang.String path, int inSampleSize)
Decodes a sampled Bitmap
object from a given file, using the inSampleSize specified.
Important Note: This method is synchronous and can cause UI Thread to freeze,
use decodeBitmapFromFile(String, int, OnBitmapRendered, OnBitmapRenderFailed)
instead for an asynchronous solution.
path
- Physical path of File in the device storage.inSampleSize
- Determines how many times image resolution is divided to lower memory usage. Image aspect ratio is not affected by this parameter, just its resolution / quality is lowered.Bitmap
object, ready to use on any View or code.public static android.graphics.Bitmap decodeBitmapFromFile(java.lang.String path)
Decodes a Bitmap
object from a given file, at its original dimensions.
Important Note: This method is synchronous and can cause UI Thread to freeze,
use decodeBitmapFromFile(String, OnBitmapRendered, OnBitmapRenderFailed)
instead for an asynchronous solution.
path
- Physical path of File in the device storage.Bitmap
object, ready to use on any View or code.public static void decodeBitmapFromResource(android.content.res.Resources res, int resId, int reqWidth, int reqHeight, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Bitmap
object from a given app resource asynchronously, using the specified measures to calculate image downsample if needed.
Downsample rate is auto-increased if bitmap rendering causes an OutOfMemoryError
.res
- Resources package. You can get default resources package using ContextThemeWrapper.getResources()
inside an activity or Context.getResources()
outside if a Context
is available.resId
- App resource id. Could be either the pure integer value, or the Android resource name (R.drawable.img_name).reqWidth
- Required width of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.reqHeight
- Required height of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void decodeBitmapFromResource(android.content.res.Resources res, int resId, int inSampleSize, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Bitmap
object from a given app resource asynchronously, using the inSampleSize specified.
Downsample rate is auto-increased if bitmap rendering causes an OutOfMemoryError
.res
- Resources package. You can get default resources package using ContextThemeWrapper.getResources()
inside an activity or Context.getResources()
outside if a Context
is available.resId
- App resource id. Could be either the pure integer value, or the Android resource name (R.drawable.img_name).inSampleSize
- Determines how many times image resolution is divided to lower memory usage. Image aspect ratio is not affected by this parameter, just its resolution / quality is lowered.onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void decodeBitmapFromResource(android.content.res.Resources res, int resId, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Bitmap
object from a given app resource asynchronously, at its original dimensions.
Downsample rate is auto-increased if bitmap rendering causes an OutOfMemoryError
.res
- Resources package. You can get default resources package using ContextThemeWrapper.getResources()
inside an activity or Context.getResources()
outside if a Context
is available.resId
- App resource id. Could be either the pure integer value, or the Android resource name (R.drawable.img_name).onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void decodeBitmapFromFile(java.lang.String path, int reqWidth, int reqHeight, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled Bitmap
object from a given file asynchronously, using the specified measures to calculate image downsample if needed.
Downsample rate is auto-increased if bitmap rendering causes an OutOfMemoryError
.
Permissions: If file is outside app's own folders, this method requires the app using the library to get permission android.permissions.READ_EXTERNAL_STORAGE in order to work. If permission android.permissions.WRITE_EXTERNAL_STORAGE is granted, READ_EXTERNAL_STORAGE permission is also granted automatically.
path
- Physical path of File in the device storage.reqWidth
- Required width of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.reqHeight
- Required height of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void decodeBitmapFromFile(java.lang.String path, int inSampleSize, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled Bitmap
object from a given file asynchronously, using the inSampleSize specified.
Downsample rate is auto-increased if bitmap rendering causes an OutOfMemoryError
.
Permissions: If file is outside app's own folders, this method requires the app using the library to get permission android.permissions.READ_EXTERNAL_STORAGE in order to work. If permission android.permissions.WRITE_EXTERNAL_STORAGE is granted, READ_EXTERNAL_STORAGE permission is also granted automatically.
path
- Physical path of File in the device storage.inSampleSize
- Determines how many times image resolution is divided to lower memory usage. Image aspect ratio is not affected by this parameter, just its resolution / quality is lowered.onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void decodeBitmapFromFile(java.lang.String path, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a Bitmap
object from a given file asynchronously, at its original dimensions.
Downsample rate is auto-increased if bitmap rendering causes an OutOfMemoryError
.
Permissions: If file is outside app's own folders, this method requires the app using the library to get permission android.permissions.READ_EXTERNAL_STORAGE in order to work. If permission android.permissions.WRITE_EXTERNAL_STORAGE is granted, READ_EXTERNAL_STORAGE permission is also granted automatically.
path
- Physical path of File in the device storage.onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void decodeBitmapFromUrl(java.lang.String url, int reqWidth, int reqHeight, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled Bitmap
object from a given url, using the specified measures to calculate image downsample if needed.
Permissions: This method requires the app using the library to use permission android.permissions.INTERNET in order to work.
url
- Image resource URL (e.g. http://www.website.com/image.png)reqWidth
- Required width of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.reqHeight
- Required height of the view where the Bitmap should fit. This parameter doesn't affect image aspect ratio, it's only used to calculate the inSampleSize of the image in case a downsample is required.onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void decodeBitmapFromUrl(java.lang.String url, int inSampleSize, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a sampled Bitmap
object from a given url, using the inSampleSize specified.
Permissions: This method requires the app using the library to use permission android.permissions.INTERNET in order to work.
url
- Image resource URL (e.g. http://www.website.com/image.png)inSampleSize
- Determines how many times image resolution is divided to lower memory usage. Image aspect ratio is not affected by this parameter, just its resolution / quality is lowered.onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void decodeBitmapFromUrl(java.lang.String url, OnBitmapRendered onBitmapRendered, OnBitmapRenderFailed onBitmapRenderFailed)
Decodes a Bitmap
object from a given url, at its original dimensions.
Permissions: This method requires the app using the library to use permission android.permissions.INTERNET in order to work.
url
- Image resource URL (e.g. http://www.website.com/image.png)onBitmapRendered
- Overwrite this callback to retrieve Bitmap
object rendered once it's ready and perform any other actions needed.onBitmapRenderFailed
- Overwrite this callback to perform actions when Bitmap
object fails to render. Can be null.public static void initDiskCache(android.content.Context context)
Initializes disk caches.
Important Note: Until an alternative is found, this method must be called (Just once for whole app life cycle, and in any time)
before using any render method, other way, Bitmap
objects rendered won't be stored on disk cache, just in memory cache.
context
- Context
from where lib is being called. This is used to get application's cache dir for disk cache.public static int calculateInSampleSize(android.graphics.BitmapFactory.Options options, int reqWidth, int reqHeight)
options
- BitmapFactory.Options
object containing image info.reqWidth
- Required width of the view where the Bitmap should fit.reqHeight
- Required height of the view where the Bitmap should fit.