Class DynamicBitmapUtils
java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicBitmapUtils
Helper class to perform
Bitmap operations.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault sample size to decode the bitmap.static final intDefault sample size to decode the logo bitmap.static final intDefault size to decode the bitmap. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BitmapapplyColorFilter(Bitmap bitmap, int color) Apply monochrome color filter on the supplied bitmap.static BitmapapplyColorFilter(Bitmap bitmap, ColorFilter colorFilter) Apply color filter on the supplied bitmap.static BitmapcreateBitmap(View view) Creates a bitmap from the supplied view.static BitmapcreateBitmap(View view, int width, int height) Creates a bitmap from the supplied view.static BitmapcropBitmap(Bitmap bitmap, int newWidth, int newHeight) Crop bitmap to the new width and height.static BitmapRetrieve the bitmap from the supplied URI.static BitmapgetBitmap(Context context, Uri uri, BitmapFactory.Options options) Retrieve the bitmap from the supplied URI.static BitmapGet bitmap from the supplied drawable.static BitmapGet bitmap from the supplied drawable.static BitmapGet bitmap from the supplied drawable.static BitmapGet bitmap from the supplied drawable.static BitmapgetBitmapLogo(Context context, Uri uri) Retrieve the compressed bitmap from the supplied URI.static intgetDominantColor(Bitmap bitmap) Extract the dominant color from the supplied bitmap.static BitmapresizeBitmap(Bitmap bitmap, int newWidth, int newHeight) Resize bitmap to the new width and height.static BitmapresizeBitmap(Bitmap bitmap, int newWidth, int newHeight, int maxWidth, int maxHeight) Resize bitmap to the new width and height.static BitmapresizeBitmap(Bitmap bitmap, int newWidth, int newHeight, int maxWidth, int maxHeight, boolean recycle) Resize bitmap to the new width and height.static BitmapresizeBitmapMax(Bitmap bitmap, int maxWidth, int maxHeight) Resize bitmap according to the max width and height.static BitmapresizeBitmapMax(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-trueto 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-trueto 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-trueto 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-trueto 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.
-