public final class BitmapUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static android.graphics.Bitmap |
clipCircle(android.graphics.Bitmap bitmap)
Clips the corners of a bitmap in order to transform it into a round shape.
|
static android.graphics.Bitmap |
clipCircle(android.graphics.Bitmap bitmap,
int size)
Clips the corners of a bitmap in order to transform it into a round shape.
|
static android.graphics.Bitmap |
clipCircle(android.graphics.Bitmap bitmap,
int borderWidth,
int borderColor)
Clips the corners of a bitmap in order to transform it into a round shape.
|
static android.graphics.Bitmap |
clipCircle(android.graphics.Bitmap bitmap,
int size,
int borderWidth,
int borderColor)
Clips the corners of a bitmap in order to transform it into a round shape.
|
static android.graphics.Bitmap |
clipSquare(android.graphics.Bitmap bitmap)
Clips the long edge of a bitmap, if its width and height are not equal, in order to form it
into a square.
|
static android.graphics.Bitmap |
clipSquare(android.graphics.Bitmap bitmap,
int size)
Clips the long edge of a bitmap, if its width and height are not equal, in order to form it
into a square.
|
static android.graphics.Bitmap |
clipSquare(android.graphics.Bitmap bitmap,
int borderWidth,
int borderColor)
Clips the long edge of a bitmap, if its width and height are not equal, in order to transform
it into a square.
|
static android.graphics.Bitmap |
clipSquare(android.graphics.Bitmap bitmap,
int size,
int borderWidth,
int borderColor)
Clips the long edge of a bitmap, if its width and height are not equal, in order to transform
it into a square.
|
static android.graphics.Bitmap |
colorToBitmap(int width,
int height,
int color)
Creates and returns a bitmap from a specific color.
|
static byte[] |
compressToByteArray(android.graphics.Bitmap bitmap,
android.graphics.Bitmap.CompressFormat format,
int quality)
Compresses a specific bitmap and returns it as a byte array.
|
static void |
compressToFile(android.graphics.Bitmap bitmap,
java.io.File file,
android.graphics.Bitmap.CompressFormat format,
int quality)
Compresses a specific bitmap and stores it within a file.
|
static android.graphics.Bitmap |
drawableToBitmap(android.graphics.drawable.Drawable drawable)
Creates and returns a bitmap from a specific drawable.
|
static <any> |
getImageDimensions(android.content.Context context,
int resourceId)
Returns the width and height of a specific image resource.
|
static <any> |
getImageDimensions(java.io.File file)
Returns the width and height of a specific image file.
|
static android.graphics.Bitmap |
loadThumbnail(android.content.Context context,
int resourceId,
int maxWidth,
int maxHeight)
Loads a downsampled thumbnail of a specific image resource while maintaining its aspect
ratio.
|
static android.graphics.Bitmap |
loadThumbnail(java.io.File file,
int maxWidth,
int maxHeight)
Loads a downsampled thumbnail of a specific image file while maintaining its aspect ratio.
|
static android.graphics.Bitmap |
resize(android.graphics.Bitmap bitmap,
int width,
int height)
Resizes a bitmap to a specific width and height.
|
static <any> |
splitHorizontally(android.graphics.Bitmap bitmap)
Splits a specific bitmap horizontally at half.
|
static <any> |
splitHorizontally(android.graphics.Bitmap bitmap,
int splitPoint)
Splits a specific bitmap horizontally at a specific split point.
|
static <any> |
splitVertically(android.graphics.Bitmap bitmap)
Splits a specific bitmap vertically at half.
|
static <any> |
splitVertically(android.graphics.Bitmap bitmap,
int splitPoint)
Splits a specific bitmap vertically at a specific split point.
|
static android.graphics.Bitmap |
textToBitmap(android.content.Context context,
int width,
int height,
int backgroundColor,
java.lang.CharSequence text,
float textSize,
int textColor)
Creates and returns a bitmap from a specific text.
|
static android.graphics.Bitmap |
textToBitmap(android.content.Context context,
int width,
int height,
int backgroundColor,
java.lang.CharSequence text,
float textSize,
int textColor,
android.graphics.Typeface typeface)
Creates and returns a bitmap from a specific text.
|
static android.graphics.Bitmap |
tile(android.graphics.Bitmap bitmap,
int width,
int height)
Creates and returns a bitmap with a specific width and height by tiling another bitmap.
|
static android.graphics.Bitmap |
tint(android.graphics.Bitmap bitmap,
int color)
Creates and returns a bitmap by overlaying it with a specific color.
|
public static android.graphics.Bitmap clipCircle(android.graphics.Bitmap bitmap)
bitmap - The bitmap, which should be clipped, as an instance of the class Bitmap. The
bitmap may not be nullBitmappublic static android.graphics.Bitmap clipCircle(android.graphics.Bitmap bitmap,
int size)
bitmap - The bitmap, which should be clipped, as an instance of the class Bitmap. The
bitmap may not be nullsize - The size, the bitmap should be resized to, as an Integer value in pixels. The
size must be at least 1Bitmappublic static android.graphics.Bitmap clipCircle(android.graphics.Bitmap bitmap,
int borderWidth,
int borderColor)
bitmap - The bitmap, which should be clipped, as an instance of the class Bitmap. The
bitmap may not be nullborderWidth - The width of the border as an Integer value in pixels. The width must be at
least 0borderColor - The color of the border as an Integer valueBitmappublic static android.graphics.Bitmap clipCircle(android.graphics.Bitmap bitmap,
int size,
int borderWidth,
int borderColor)
bitmap - The bitmap, which should be clipped, as an instance of the class Bitmap. The
bitmap may not be nullsize - The size, the bitmap should be resized to, as an Integer value in pixels. The
size must be at least 1borderWidth - The width of the border as an Integer value in pixels. The width must be at
least 0borderColor - The color of the border as an Integer valueBitmappublic static android.graphics.Bitmap clipSquare(android.graphics.Bitmap bitmap)
bitmap - The bitmap, which should be clipped, as an instance of the class Bitmap. The
bitmap may not be nullBitmappublic static android.graphics.Bitmap clipSquare(android.graphics.Bitmap bitmap,
int size)
bitmap - The bitmap, which should be clipped, as an instance of the class Bitmap. The
bitmap may not be nullsize - The size, the bitmap should be resized to, as an Integer value in pixels. The
size must be at least 1Bitmappublic static android.graphics.Bitmap clipSquare(android.graphics.Bitmap bitmap,
int borderWidth,
int borderColor)
bitmap - The bitmap, which should be clipped, as an instance of the class Bitmap. The
bitmap may not be nullborderWidth - The width of the border as an Integer value in pixels. The width must be at
least 0borderColor - The color of the border as an Integer valueBitmappublic static android.graphics.Bitmap clipSquare(android.graphics.Bitmap bitmap,
int size,
int borderWidth,
int borderColor)
bitmap - The bitmap, which should be clipped, as an instance of the class Bitmap. The
bitmap may not be nullsize - The size, the bitmap should be resized to, as an Integer value in pixels. The
size must be at least 1borderWidth - The width of the border as an Integer value in pixels. The width must be at
least 0borderColor - The color of the border as an Integer valueBitmappublic static android.graphics.Bitmap resize(android.graphics.Bitmap bitmap,
int width,
int height)
bitmap - The bitmap, which should be resized, as an instance of the class Bitmap. The
bitmap may not be nullwidth - The width, the bitmap should be resized to, as an Integer value in pixels.
The width must be at least 1height - The height, the bitmap should be resized to, as an Integer value in pixels.
The height must be at least 1Bitmappublic static <any> splitHorizontally(android.graphics.Bitmap bitmap)
bitmap - The bitmap, which should be split, as an instance of the class Bitmap. The
bitmap may not be nullpublic static <any> splitHorizontally(android.graphics.Bitmap bitmap,
int splitPoint)
bitmap - The bitmap, which should be split, as an instance of the class Bitmap. The
bitmap may not be nullsplitPoint - The row, the bitmap should be split at, counted from the top edge in pixels as an
Integer valuepublic static <any> splitVertically(android.graphics.Bitmap bitmap)
bitmap - The bitmap, which should be split, as an instance of the class Bitmap. The
bitmap may not be nullpublic static <any> splitVertically(android.graphics.Bitmap bitmap,
int splitPoint)
bitmap - The bitmap, which should be split, as an instance of the class Bitmap. The
bitmap may not be nullsplitPoint - The column, the bitmap should be split at, counted from the left edge in pixels as an
Integer valuepublic static android.graphics.Bitmap tile(android.graphics.Bitmap bitmap,
int width,
int height)
bitmap - The bitmap, which should be tiled, as an instance of the class Bitmap. The
bitmap may not be nullwidth - The width of the bitmap as an Integer value in pixels. The width must be at
least 1height - The height of the bitmap as an Integer value in pixels. The height must be at
least 1Bitmappublic static android.graphics.Bitmap tint(android.graphics.Bitmap bitmap,
int color)
bitmap - The bitmap, which should be tinted, as an instance of the class Bitmap. The
bitmap may not be nullcolor - The color, which should be used for tinting, as an Integer valueBitmappublic static android.graphics.Bitmap drawableToBitmap(android.graphics.drawable.Drawable drawable)
drawable - The drawable, which should be converted, as an instance of the class Drawable. The drawable may not be nullBitmappublic static android.graphics.Bitmap textToBitmap(android.content.Context context,
int width,
int height,
int backgroundColor,
java.lang.CharSequence text,
float textSize,
int textColor)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullwidth - The width of the bitmap, which should be created, in pixels as an Integer
valueheight - The height of the bitmap, which should be created, in pixels as an Integer
valuebackgroundColor - The background color of the bitmap, which should be created, as an Integer
valuetext - The text, the bitmap should be created from, as an instance of the type CharSequence. The text may neither be null, nor emptytextSize - The text size, which should be used, in sp as an Integer valuetextColor - The text color, which should be used, as an Integer value The color of the
textBitmappublic static android.graphics.Bitmap textToBitmap(android.content.Context context,
int width,
int height,
int backgroundColor,
java.lang.CharSequence text,
float textSize,
int textColor,
android.graphics.Typeface typeface)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullwidth - The width of the bitmap, which should be created, in pixels as an Integer
valueheight - The height of the bitmap, which should be created, in pixels as an Integer
valuebackgroundColor - The background color of the bitmap, which should be created, as an Integer
valuetext - The text, the bitmap should be created from, as an instance of the type CharSequence. The text may neither be null, nor emptytextSize - The text size, which should be used, in sp as an Integer valuetextColor - The text color, which should be used, as an Integer value The color of the
texttypeface - The typeface, which should be used, as a value of the enum Typeface or null,
if the default typeface should be usedBitmappublic static android.graphics.Bitmap colorToBitmap(int width,
int height,
int color)
width - The width of the bitmap, which should be created, in pixels as an Integer
value. The width must be at least 1height - The height of the bitmap, which should be created, in pixels as an Integer
value. The height must be at least 1color - The color, which should be used, as an Integer valueBitmappublic static <any> getImageDimensions(java.io.File file)
throws java.io.IOException
file - The image file, whose width and height should be returned, as an instance of the
class File. The file may not be null. The file must exist and must not be a
directoryjava.io.IOException - The exception, which is thrown, if an error occurs while decoding the image filepublic static <any> getImageDimensions(android.content.Context context,
int resourceId)
throws java.io.IOException
context - The context, which should be used, as an instance of the class Context. The
context may not be nullresourceId - The resource id of the image resource, whose width and height should be returned, as
an Integer value. The resource id must correspond to a valid drawable
resourcejava.io.IOException - The exception, which is thrown, if an error occurs while decoding the image resourcepublic static android.graphics.Bitmap loadThumbnail(java.io.File file,
int maxWidth,
int maxHeight)
throws java.io.IOException
file - The image file, which should be loaded, as an instance of the class File. The
file may not be null. The file must exist and must not be a directorymaxWidth - The maximum width of the thumbnail in pixels as an Integer value. The maximum
width must be at least 1maxHeight - The maximum height of the thumbnail in pixels as an Integer value. The
maximum height must be at least 1Bitmapjava.io.IOException - The exception, which is thrown, if an error occurs while decoding the image filepublic static android.graphics.Bitmap loadThumbnail(android.content.Context context,
int resourceId,
int maxWidth,
int maxHeight)
throws java.io.IOException
context - The context, which should be used, as an instance of the class Context. The
context may not be nullresourceId - The resource id of the image resource, which should be loaded, as an Integer
value. The resource id must correspond to a valid drawable resourcemaxWidth - The maximum width of the thumbnail in pixels as an Integer value. The maximum
width must be at least 1maxHeight - The maximum height of the thumbnail in pixels as an Integer value. The
maximum height must be at least 1Bitmapjava.io.IOException - The exception, which is thrown, if an error occurs while decoding the image resourcepublic static void compressToFile(android.graphics.Bitmap bitmap,
java.io.File file,
android.graphics.Bitmap.CompressFormat format,
int quality)
throws java.io.IOException
bitmap - The bitmap, which should be compressed, as an instance of the class Bitmap.
The bitmap may not be nullfile - The file, the bitmap should be compressed to, as an instance of the class File. The file may not be nullformat - The format, which should be used to compress the bitmap, as a value of the enum
Bitmap.CompressFormat. The format must either be JPEG, PNG
or WEBPquality - The quality, which should be used to compress the bitmap, as an Integer
value. The quality must be at least 0 (lowest quality) and at maximum 100 (highest
quality)java.io.FileNotFoundException - The exception, which is thrown, if the given file could not be opened for writingjava.io.IOException - The exception, which is thrown, if an error occurs while compressing the bitmappublic static byte[] compressToByteArray(android.graphics.Bitmap bitmap,
android.graphics.Bitmap.CompressFormat format,
int quality)
throws java.io.IOException
bitmap - The bitmap, which should be compressed, as an instance of the class Bitmap.
The bitmap may not be nullformat - The format, which should be used to compress the bitmap, as a value of the enum
Bitmap.CompressFormat. The format must either be JPEG, PNG
or WEBPquality - The quality, which should be used to compress the bitmap, as an Integer
value. The quality must be at least 0 (lowest quality) and at maximum 100 (highest
quality)Byte arrayjava.io.IOException - The exception, which is thrown, if an error occurs while compressing the bitmap