Class DynamicBitmapUtils
java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicBitmapUtils
Helper class to perform
Bitmap
operations.-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default sample size to decode the bitmap.static final int
Default sample size to decode the logo bitmap.static final int
Default size to decode the bitmap. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Bitmap
applyColorFilter
(Bitmap bitmap, int color) Apply monochrome color filter on the supplied bitmap.static Bitmap
applyColorFilter
(Bitmap bitmap, ColorFilter colorFilter) Apply color filter on the supplied bitmap.static Bitmap
createBitmap
(View view) Creates a bitmap from the supplied view.static Bitmap
createBitmap
(View view, int width, int height) Creates a bitmap from the supplied view.static Bitmap
cropBitmap
(Bitmap bitmap, int newWidth, int newHeight) Crop bitmap to the new width and height.static Bitmap
Retrieve the bitmap from the supplied URI.static Bitmap
getBitmap
(Context context, Uri uri, BitmapFactory.Options options) Retrieve the bitmap from the supplied URI.static Bitmap
Get bitmap from the supplied drawable.static Bitmap
Get bitmap from the supplied drawable.static Bitmap
Get bitmap from the supplied drawable.static Bitmap
Get bitmap from the supplied drawable.static Bitmap
getBitmapLogo
(Context context, Uri uri) Retrieve the compressed bitmap from the supplied URI.static int
getDominantColor
(Bitmap bitmap) Extract the dominant color from the supplied bitmap.static Bitmap
resizeBitmap
(Bitmap bitmap, int newWidth, int newHeight) Resize bitmap to the new width and height.static Bitmap
resizeBitmap
(Bitmap bitmap, int newWidth, int newHeight, int maxWidth, int maxHeight) Resize bitmap to the new width and height.static Bitmap
resizeBitmap
(Bitmap bitmap, int newWidth, int newHeight, int maxWidth, int maxHeight, boolean recycle) Resize bitmap to the new width and height.static Bitmap
resizeBitmapMax
(Bitmap bitmap, int maxWidth, int maxHeight) Resize bitmap according to the max width and height.static Bitmap
resizeBitmapMax
(Bitmap bitmap, int maxWidth, int maxHeight, boolean recycle) Resize bitmap according to the max width and height.
-
Field Details
-
SIZE_DEFAULT
public static final int SIZE_DEFAULTDefault size to decode the bitmap.- See Also:
-
SAMPLE_DEFAULT
public static final int SAMPLE_DEFAULTDefault sample size to decode the bitmap.- See Also:
-
SAMPLE_LOGO
public static final int SAMPLE_LOGODefault sample size to decode the logo bitmap.- See Also:
-
-
Constructor Details
-
DynamicBitmapUtils
public DynamicBitmapUtils()
-
-
Method Details
-
getBitmap
@Nullable public static Bitmap getBitmap(@Nullable Context context, @Nullable Uri uri, @Nullable BitmapFactory.Options options) Retrieve the bitmap from the supplied URI.- Parameters:
context
- The context to get the content resolver.uri
- The URI to retrieve the bitmap.options
- The bitmap factory options to be used.- Returns:
- The bitmap from the supplied URI.
- See Also:
-
getBitmap
Retrieve the bitmap from the supplied URI.- Parameters:
context
- The context to get the content resolver.uri
- The URI to retrieve the bitmap.- Returns:
- The bitmap from the supplied URI.
- See Also:
-
getBitmap
@Nullable public static Bitmap getBitmap(@Nullable Drawable drawable, int width, int height, boolean compress, int quality) Get bitmap from the supplied drawable.- Parameters:
drawable
- The drawable to get the bitmap.width
- The width in dip for the bitmap.height
- The height in dip for the bitmap.compress
-true
to compress the bitmap.quality
- The quality of the compressed bitmap.- Returns:
- The bitmap from the supplied drawable.
-
getBitmap
Get bitmap from the supplied drawable.- Parameters:
drawable
- The drawable to get the bitmap.width
- The width in dip for the bitmap.height
- The height in dip for the bitmap.- Returns:
- The bitmap from the supplied drawable.
- See Also:
-
getBitmap
@Nullable public static Bitmap getBitmap(@Nullable Drawable drawable, boolean compress, int quality) Get bitmap from the supplied drawable.- Parameters:
drawable
- The drawable to get the bitmap.compress
-true
to compress the bitmap.quality
- The quality of the compressed bitmap.- Returns:
- The bitmap from the supplied drawable.
- See Also:
-
getBitmap
Get bitmap from the supplied drawable.- Parameters:
drawable
- The drawable to get the bitmap.- Returns:
- The bitmap from the supplied drawable.
- See Also:
-
getBitmapLogo
Retrieve the compressed bitmap from the supplied URI.- Parameters:
context
- The context to get the content resolver.uri
- The URI to retrieve the bitmap.- Returns:
- The compressed bitmap from the supplied URI.
- See Also:
-
resizeBitmap
@Nullable public static Bitmap resizeBitmap(@Nullable Bitmap bitmap, int newWidth, int newHeight, int maxWidth, int maxHeight, boolean recycle) Resize bitmap to the new width and height.- Parameters:
bitmap
- The bitmap to resize.newWidth
- The new width for the bitmap.newHeight
- The new height for the bitmap.maxWidth
- The maximum width for the bitmap.maxHeight
- The maximum height for the bitmap.recycle
-true
to recycle the original bitmap.- Returns:
- The resized bitmap with new width and height.
-
resizeBitmap
@Nullable public static Bitmap resizeBitmap(@Nullable Bitmap bitmap, int newWidth, int newHeight, int maxWidth, int maxHeight) Resize bitmap to the new width and height.- Parameters:
bitmap
- The bitmap to resize.newWidth
- The new width for the bitmap.newHeight
- The new height for the bitmap.maxWidth
- The maximum width for the bitmap.maxHeight
- The maximum height for the bitmap.- Returns:
- The resized bitmap with new width and height.
- See Also:
-
resizeBitmap
Resize bitmap to the new width and height.- Parameters:
bitmap
- The bitmap to resize.newWidth
- The new width for the bitmap.newHeight
- The new height for the bitmap.- Returns:
- The resized bitmap with new width and height.
- See Also:
-
resizeBitmapMax
@Nullable public static Bitmap resizeBitmapMax(@Nullable Bitmap bitmap, int maxWidth, int maxHeight, boolean recycle) Resize bitmap according to the max width and height.- Parameters:
bitmap
- The bitmap to resize.maxWidth
- The maximum width for the bitmap.maxHeight
- The maximum height for the bitmap.recycle
-true
to recycle the original bitmap.- Returns:
- The resized bitmap according to the max width and height.
- See Also:
-
resizeBitmapMax
@Nullable public static Bitmap resizeBitmapMax(@Nullable Bitmap bitmap, int maxWidth, int maxHeight) Resize bitmap according to the max width and height.- Parameters:
bitmap
- The bitmap to resize.maxWidth
- The maximum width for the bitmap.maxHeight
- The maximum height for the bitmap.- Returns:
- The resized bitmap according to the max width and height.
- See Also:
-
cropBitmap
Crop bitmap to the new width and height.- Parameters:
bitmap
- The bitmap to crop.newWidth
- The new width for the bitmap.newHeight
- The new height for the bitmap.- Returns:
- The cropped bitmap with new width and height.
-
applyColorFilter
@Nullable public static Bitmap applyColorFilter(@Nullable Bitmap bitmap, @NonNull ColorFilter colorFilter) Apply color filter on the supplied bitmap.- Parameters:
bitmap
- The bitmap to apply color filter.colorFilter
- The color filter to be applied on the bitmap.- Returns:
- The new bitmap with applied color filter.
-
applyColorFilter
Apply monochrome color filter on the supplied bitmap.- Parameters:
bitmap
- The bitmap to apply color filter.color
- The color to generate color filter.- Returns:
- The new bitmap with applied color filter.
-
getDominantColor
Extract the dominant color from the supplied bitmap.- Parameters:
bitmap
- The bitmap to extract the dominant color.- Returns:
- The dominant color extracted from the bitmap.
-
createBitmap
Creates a bitmap from the supplied view.- Parameters:
view
- The view to get the bitmap.width
- The width for the bitmap.height
- The height for the bitmap.- Returns:
- The bitmap from the supplied drawable.
-
createBitmap
Creates a bitmap from the supplied view.- Parameters:
view
- The view to get the bitmap.- Returns:
- The bitmap from the supplied drawable.
-