public class

BitmapUtil

extends Object
java.lang.Object
   ↳ com.davidluoye.support.util.BitmapUtil

Class Overview

Provides static functions to decode bitmaps at the optimal size

Summary

Public Methods
static Bitmap decodeBitmapFromBytes(byte[] bytes, int sampleSize)
Decodes the bitmap with the given sample size
static int findOptimalSampleSize(int originalSmallerExtent, int targetExtent)
Finds the optimal sampleSize for loading the picture
static Drawable getRotatedDrawable(Resources resources, int resourceId, float angle)
Retrieves a copy of the specified drawable resource, rotated by a specified angle.
static Bitmap getRoundedBitmap(Bitmap input, int targetWidth, int targetHeight)
Given an input bitmap, scales it to the given width/height and makes it round.
static int getSmallerExtentFromBytes(byte[] bytes)
Returns Width or Height of the picture, depending on which size is smaller.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static Bitmap decodeBitmapFromBytes (byte[] bytes, int sampleSize)

Decodes the bitmap with the given sample size

public static int findOptimalSampleSize (int originalSmallerExtent, int targetExtent)

Finds the optimal sampleSize for loading the picture

Parameters
originalSmallerExtent Width or height of the picture, whichever is smaller
targetExtent Width or height of the target view, whichever is bigger. If either one of the parameters is 0 or smaller, no sampling is applied

public static Drawable getRotatedDrawable (Resources resources, int resourceId, float angle)

Retrieves a copy of the specified drawable resource, rotated by a specified angle.

Parameters
resources The current resources.
resourceId The resource ID of the drawable to rotate.
angle The angle of rotation.
Returns
  • Rotated drawable.

public static Bitmap getRoundedBitmap (Bitmap input, int targetWidth, int targetHeight)

Given an input bitmap, scales it to the given width/height and makes it round.

Parameters
input Bitmap to scale and crop
targetWidth desired output width
targetHeight desired output height
Returns
  • output bitmap scaled to the target width/height and cropped to an oval. The cropping algorithm will try to fit as much of the input into the output as possible, while preserving the target width/height ratio.

public static int getSmallerExtentFromBytes (byte[] bytes)

Returns Width or Height of the picture, depending on which size is smaller. Doesn't actually decode the picture, so it is pretty efficient to run.