public class ImageUtils
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ImageUtils.InputStreamFactory
Utility class for when an InputStream needs to be read multiple times.
|
| Constructor and Description |
|---|
ImageUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int |
calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
Calculate an inSampleSize for use in a
BitmapFactory.Options object when decoding
bitmaps using the decode* methods from BitmapFactory. |
static ImageUtils.InputStreamFactory |
createInputStreamFactory(android.content.ContentResolver resolver,
android.net.Uri uri) |
static android.graphics.Bitmap |
decodeSampledBitmapFromDescriptor(java.io.FileDescriptor fileDescriptor)
Decode and sample down a bitmap from a file input stream to the requested width and height.
|
static android.graphics.Bitmap |
decodeSampledBitmapFromDescriptor(java.io.FileDescriptor fileDescriptor,
int reqWidth,
int reqHeight)
Decode and sample down a bitmap from a file input stream to the requested width and height.
|
static android.graphics.Bitmap |
decodeStream(android.content.ContentResolver resolver,
android.net.Uri uri,
android.graphics.BitmapFactory.Options opts)
Create a bitmap from a local URI
|
static android.graphics.Bitmap |
decodeStream(android.content.ContentResolver resolver,
android.net.Uri uri,
int maxSize)
Create a bitmap from a local URI
|
static android.graphics.Bitmap |
decodeStream(ImageUtils.InputStreamFactory factory,
android.graphics.Rect outPadding,
android.graphics.BitmapFactory.Options opts)
Wrapper around
BitmapFactory.decodeStream(InputStream, Rect,
BitmapFactory.Options) that returns null on OutOfMemoryError. |
static android.graphics.Bitmap |
decodeStream(java.io.InputStream is,
android.graphics.Rect outPadding,
android.graphics.BitmapFactory.Options opts)
Wrapper around
BitmapFactory.decodeStream(InputStream, Rect,
BitmapFactory.Options) that returns null on OutOfMemoryError. |
static int |
findBestSampleSize(int actualWidth,
int actualHeight,
int desiredWidth,
int desiredHeight)
Returns the largest power-of-two divisor for use in downscaling a bitmap
that will not result in the scaling past the desired dimensions.
|
static android.graphics.Point |
getImageBounds(ImageUtils.InputStreamFactory factory)
Gets the image bounds
|
static boolean |
isImageMimeType(java.lang.String mimeType) |
public static int findBestSampleSize(int actualWidth,
int actualHeight,
int desiredWidth,
int desiredHeight)
actualWidth - Actual width of the bitmapactualHeight - Actual height of the bitmapdesiredWidth - Desired width of the bitmapdesiredHeight - Desired height of the bitmappublic static android.graphics.Bitmap decodeSampledBitmapFromDescriptor(java.io.FileDescriptor fileDescriptor,
int reqWidth,
int reqHeight)
fileDescriptor - The file descriptor to read fromreqWidth - The requested width of the resulting bitmapreqHeight - The requested height of the resulting bitmappublic static android.graphics.Bitmap decodeSampledBitmapFromDescriptor(java.io.FileDescriptor fileDescriptor)
fileDescriptor - The file descriptor to read frompublic static int calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
BitmapFactory.Options object when decoding
bitmaps using the decode* methods from BitmapFactory. This implementation calculates
the closest inSampleSize that is a power of 2 and will result in the final decoded bitmap
having a width and height equal to or larger than the requested width and height.options - An options object with out* params already populated (run through a decode*
method with inJustDecodeBounds==truereqWidth - The requested width of the resulting bitmapreqHeight - The requested height of the resulting bitmappublic static boolean isImageMimeType(java.lang.String mimeType)
public static android.graphics.Bitmap decodeStream(android.content.ContentResolver resolver,
android.net.Uri uri,
int maxSize)
resolver - The ContentResolveruri - The local URImaxSize - The maximum size (either width or height)public static android.graphics.Bitmap decodeStream(android.content.ContentResolver resolver,
android.net.Uri uri,
android.graphics.BitmapFactory.Options opts)
resolver - The ContentResolveruri - The local URImaxSize - The maximum size (either width or height)public static android.graphics.Bitmap decodeStream(java.io.InputStream is,
android.graphics.Rect outPadding,
android.graphics.BitmapFactory.Options opts)
BitmapFactory.decodeStream(InputStream, Rect,
BitmapFactory.Options) that returns null on OutOfMemoryError.is - The input stream that holds the raw data to be decoded into a
bitmap.outPadding - If not null, return the padding rect for the bitmap if
it exists, otherwise set padding to [-1,-1,-1,-1]. If
no bitmap is returned (null) then padding is
unchanged.opts - null-ok; Options that control downsampling and whether the
image should be completely decoded, or just is size returned.public static android.graphics.Bitmap decodeStream(ImageUtils.InputStreamFactory factory, android.graphics.Rect outPadding, android.graphics.BitmapFactory.Options opts) throws java.io.FileNotFoundException
BitmapFactory.decodeStream(InputStream, Rect,
BitmapFactory.Options) that returns null on OutOfMemoryError.factory - Used to create input streams that holds the raw data to be decoded into a
bitmap.outPadding - If not null, return the padding rect for the bitmap if
it exists, otherwise set padding to [-1,-1,-1,-1]. If
no bitmap is returned (null) then padding is
unchanged.opts - null-ok; Options that control downsampling and whether the
image should be completely decoded, or just is size returned.java.io.FileNotFoundExceptionpublic static android.graphics.Point getImageBounds(ImageUtils.InputStreamFactory factory) throws java.io.IOException
factory - Used to create the InputStream.java.io.IOExceptionpublic static ImageUtils.InputStreamFactory createInputStreamFactory(android.content.ContentResolver resolver, android.net.Uri uri)