public final class

ImageUtils

extends Object
java.lang.Object
   ↳ com.urbanairship.util.ImageUtils

Class Overview

A class containing utility methods related to bitmaps.

Summary

Nested Classes
class ImageUtils.DrawableResult Drawable result. 
Public Methods
static int calculateInSampleSize(int width, int height, int reqWidth, int reqHeight)
Calculate the largest inSampleSize value that is a power of 2 and keeps both height and width larger than the requested height and width.
static ImageUtils.Size calculateTargetSize(int width, int height, int reqWidth, int reqHeight, int fallbackWidth, int fallbackHeight)
Calculates a target size based on the original image aspect ratio if either the request width or request height are 0, otherwise returns the request size.
static Bitmap fetchScaledBitmap(Context context, URL url, int reqWidth, int reqHeight)
Create a scaled bitmap.
static Bitmap fetchScaledBitmap(Context context, URL url, int reqWidth, int reqHeight, int fallbackWidth, int fallbackHeight)
Create a scaled bitmap.
static ImageUtils.DrawableResult fetchScaledDrawable(Context context, URL url, int reqWidth, int reqHeight, int fallbackWidth, int fallbackHeight)
Fetches a drawable from an image path, using the supplied fallback dimensions if the ImageView reports a width or height of zero.
static ImageUtils.DrawableResult fetchScaledDrawable(Context context, URL url, int reqWidth, int reqHeight)
Fetches a drawable from an image path.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static int calculateInSampleSize (int width, int height, int reqWidth, int reqHeight)

Calculate the largest inSampleSize value that is a power of 2 and keeps both height and width larger than the requested height and width.

Taken from http://developer.android.com/training/displaying-bitmaps/load-bitmap.html.

Parameters
width The width of the image.
height The height of the image.
reqWidth The requested width of the image.
reqHeight The requested height of the image.
Returns
  • The calculated inSampleSize.

public static ImageUtils.Size calculateTargetSize (int width, int height, int reqWidth, int reqHeight, int fallbackWidth, int fallbackHeight)

Calculates a target size based on the original image aspect ratio if either the request width or request height are 0, otherwise returns the request size.

Parameters
width The width of the image.
height The height of the image.
reqWidth The requested width of the image.
reqHeight The requested height of the image.
Returns
  • The target Size.

public static Bitmap fetchScaledBitmap (Context context, URL url, int reqWidth, int reqHeight)

Create a scaled bitmap.

Parameters
context The application context.
url The URL image.
reqWidth The requested width of the image.
reqHeight The requested height of the image.
Returns
  • The scaled bitmap.
Throws
IOException if file fails to be created.

public static Bitmap fetchScaledBitmap (Context context, URL url, int reqWidth, int reqHeight, int fallbackWidth, int fallbackHeight)

Create a scaled bitmap.

Parameters
context The application context.
url The URL image.
reqWidth The requested width of the image.
reqHeight The requested height of the image.
fallbackWidth The width dimension to be used if the ImageView reports a width of zero.
fallbackHeight The height dimension to be used if the ImageView reports a height of zero.
Returns
  • The scaled bitmap.
Throws
IOException if file fails to be created.

public static ImageUtils.DrawableResult fetchScaledDrawable (Context context, URL url, int reqWidth, int reqHeight, int fallbackWidth, int fallbackHeight)

Fetches a drawable from an image path, using the supplied fallback dimensions if the ImageView reports a width or height of zero. Setting the fallback dimensions to -1 will automatically calculate zero dimensions based on the aspect ratio of the image.

Parameters
context The application context.
url The URL.
reqWidth The requested width of the image.
reqHeight The requested height of the image.
fallbackWidth The width dimension to be used if the ImageView reports a width of zero.
fallbackHeight The height dimension to be used if the ImageView reports a height of zero.
Returns
  • The result or null if the file was unable to be downloaded.
Throws
IOException if file fails to be created.

public static ImageUtils.DrawableResult fetchScaledDrawable (Context context, URL url, int reqWidth, int reqHeight)

Fetches a drawable from an image path.

Parameters
context The application context.
url The URL.
reqWidth The requested width of the image.
reqHeight The requested height of the image.
Returns
  • The result or null if the file was unable to be downloaded.
Throws
IOException if file fails to be created.