public class ImageUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MESSAGE_ERROR |
static int |
MESSAGE_OK |
| Constructor and Description |
|---|
ImageUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int |
calculateInSampleSize(android.graphics.BitmapFactory.Options options,
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 android.content.Intent |
getImageCaptureIntent(android.content.Context context,
java.io.File captureToFile)
Create a new
Intent for capturing an image. |
static android.content.Intent |
getImageCropIntent(java.io.File inputCropFile,
java.io.File outputCropFile)
Create a new
Intent for cropping an image. |
static android.content.Intent |
getImagePickerIntent()
Create a new
Intent for picking an image. |
static int |
getOrientation(android.content.ContentResolver contentResolver,
android.net.Uri uri) |
static int |
getPixelsFromDP(android.content.res.Resources resources,
float dps)
Get the number of pixels scaled for the current density.
|
static android.graphics.Bitmap |
loadImageAtRequiredSize(android.content.ContentResolver contentResolver,
android.net.Uri uri,
int reqWidth,
int reqHeight)
Load an image from the given file at a size that will equal or exceed the given bounds.
|
static android.graphics.Bitmap |
loadImageAtRequiredSize(java.io.File imageFile,
int reqWidth,
int reqHeight)
Load an image from the given file at a size that will equal or exceed the given bounds.
|
static android.graphics.Bitmap |
loadImageAtRequiredSize(java.io.File imageFile,
int reqWidth,
int reqHeight,
DonkyListener listener)
Load an image from the given file at a size that will equal or exceed the given bounds.
|
static android.graphics.BitmapFactory.Options |
readImageBounds(android.content.ContentResolver contentResolver,
android.net.Uri uri)
Read the image size from the given file.
|
static android.graphics.BitmapFactory.Options |
readImageBounds(java.io.File file)
Read the image size from the given file.
|
static android.graphics.Bitmap |
resizeBitmap(android.graphics.Bitmap b,
int maxWidth,
int maxHeight,
boolean allowLossOfPrecision)
Try to resize the given bitmap in memory, keeping it's aspect ratio to the given max dimensions.
|
static void |
resizeBitmap(java.io.File imageFile,
int maxWidth,
int maxHeight,
int jpegQuality)
Resize the given bitmap, if it is larger than the given width or height.
|
static void |
resizeBitmapToPNG(java.io.File imageFile,
int maxWidth,
int maxHeight)
Resize the given bitmap, if it is larger than the given width or height.
|
static void |
saveBitmapContent(android.content.ContentResolver contentResolver,
android.content.Intent data,
java.io.File outputFile,
android.os.Handler handler)
Save a bitmap picked from the image picker to the given file in a background thread.
|
static void |
saveBitmapContent(android.content.ContentResolver contentResolver,
android.net.Uri uri,
java.io.File outputFile,
android.os.Handler handler)
Save a bitmap picked from the image picker to the given file in a background thread.
|
public static final int MESSAGE_OK
public static final int MESSAGE_ERROR
public static android.content.Intent getImageCaptureIntent(android.content.Context context,
java.io.File captureToFile)
Intent for capturing an image.context - The current context.captureToFile - The file to write the image to.public static android.content.Intent getImageCropIntent(java.io.File inputCropFile,
java.io.File outputCropFile)
Intent for cropping an image.inputCropFile - The image file to crop.outputCropFile - The image file to crop. Need to specify a different output directorypublic static android.content.Intent getImagePickerIntent()
Intent for picking an image.public static void saveBitmapContent(android.content.ContentResolver contentResolver,
android.content.Intent data,
java.io.File outputFile,
android.os.Handler handler)
MESSAGE_OK,
or will have a what of MESSAGE_ERROR on an error with the obj set to the Exception.contentResolver - The ContentResolver.data - The data intent from the Activity.onActivityResult(int, int, Intent).outputFile - The file to save the image to.handler - The handler to call back when finished.getImagePickerIntent()public static void saveBitmapContent(android.content.ContentResolver contentResolver,
android.net.Uri uri,
java.io.File outputFile,
android.os.Handler handler)
MESSAGE_OK,
or will have a what of MESSAGE_ERROR on an error with the obj set to the Exception.contentResolver - The ContentResolver.uri - The uri from the data intent from the Activity.onActivityResult(int, int, Intent).outputFile - The file to save the image to.handler - The handler to call back when finished.getImagePickerIntent()public static int getOrientation(android.content.ContentResolver contentResolver,
android.net.Uri uri)
public static android.graphics.Bitmap loadImageAtRequiredSize(java.io.File imageFile,
int reqWidth,
int reqHeight)
imageFile - The file to load.reqWidth - The required width.reqHeight - The required height.public static android.graphics.Bitmap loadImageAtRequiredSize(java.io.File imageFile,
int reqWidth,
int reqHeight,
DonkyListener listener)
imageFile - The file to load.reqWidth - The required width.reqHeight - The required height.listener - The listener for throwable eventspublic static android.graphics.Bitmap loadImageAtRequiredSize(android.content.ContentResolver contentResolver,
android.net.Uri uri,
int reqWidth,
int reqHeight)
reqWidth - The required width.reqHeight - The required height.public static void resizeBitmap(java.io.File imageFile,
int maxWidth,
int maxHeight,
int jpegQuality)
throws java.io.FileNotFoundException
imageFile - The file to resize.maxWidth - The max width.maxHeight - The max height.jpegQuality - The quality to save at.java.io.FileNotFoundException - If the file does not exist, or we cannot decode a bitmap from it.public static void resizeBitmapToPNG(java.io.File imageFile,
int maxWidth,
int maxHeight)
throws java.io.FileNotFoundException
imageFile - The file to resize.maxWidth - The max width.maxHeight - The max height.java.io.FileNotFoundException - If the file does not exist, or we cannot decode a bitmap from it.public static android.graphics.BitmapFactory.Options readImageBounds(java.io.File file)
file - The file to read.public static android.graphics.BitmapFactory.Options readImageBounds(android.content.ContentResolver contentResolver,
android.net.Uri uri)
uri - The file to read.public static int calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
options - The bitmap options (to get the actual height and width of the image)reqWidth - The required width.reqHeight - The required height.public static int getPixelsFromDP(android.content.res.Resources resources,
float dps)
resources - The Resources.dps - Number of pixels in mdpi.public static android.graphics.Bitmap resizeBitmap(android.graphics.Bitmap b,
int maxWidth,
int maxHeight,
boolean allowLossOfPrecision)
b - The bitmap to scale.maxWidth - The max width.maxHeight - The max height.