Class DynamicBitmapUtils

java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicBitmapUtils

public class DynamicBitmapUtils extends Object
Helper class to perform Bitmap operations.
  • Field Details

    • SIZE_DEFAULT

      public static final int SIZE_DEFAULT
      Default size to decode the bitmap.
      See Also:
    • SAMPLE_DEFAULT

      public static final int SAMPLE_DEFAULT
      Default sample size to decode the 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

      @Nullable public static Bitmap getBitmap(@Nullable Context context, @Nullable Uri uri)
      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

      @Nullable public static Bitmap getBitmap(@Nullable Drawable drawable, int width, int height)
      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

      @Nullable public static Bitmap getBitmap(@Nullable Drawable drawable)
      Get bitmap from the supplied drawable.
      Parameters:
      drawable - The drawable to get the bitmap.
      Returns:
      The bitmap from the supplied drawable.
      See Also:
    • getBitmapLogo

      @Nullable public static Bitmap getBitmapLogo(@Nullable Context context, @Nullable Uri uri)
      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

      @Nullable public static Bitmap resizeBitmap(@Nullable Bitmap bitmap, int newWidth, int newHeight)
      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

      @Nullable public static Bitmap cropBitmap(@Nullable Bitmap bitmap, int newWidth, int newHeight)
      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

      @Nullable public static Bitmap applyColorFilter(@Nullable Bitmap bitmap, @ColorInt int color)
      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

      @ColorInt public static int getDominantColor(@NonNull Bitmap bitmap)
      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

      @Nullable public static Bitmap createBitmap(@Nullable View view, int width, int height)
      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

      @Nullable public static Bitmap createBitmap(@Nullable View view)
      Creates a bitmap from the supplied view.
      Parameters:
      view - The view to get the bitmap.
      Returns:
      The bitmap from the supplied drawable.