Android Utililty Methods Bitmap Scale

List of utility methods to do Bitmap Scale

Description

The list of methods to do Bitmap Scale are organized into topic(s).

Method

BitmapscaleImage(Bitmap image, float scale)
scales Bitmap to a decimal
Bitmap data = Bitmap.createBitmap((int) (image.getWidth() * scale),
        (int) (image.getHeight() * scale), image.getConfig());
Canvas canvas = new Canvas(data);
canvas.drawBitmap(image,
        new Rect(0, 0, image.getWidth(), image.getHeight()),
        new Rect(0, 0, (int) (image.getWidth() * scale),
                (int) (image.getHeight() * scale)), null);
return data;
...
BitmapscaleImg(Bitmap bitmap, float scale)
scale Img
Bitmap resizeBmp = null;
try {
    int bmpW = bitmap.getWidth();
    int bmpH = bitmap.getHeight();
    Matrix mt = new Matrix();
    mt.postScale(scale, scale);
    resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, mt,
            true);
...
BitmapscaleImg(Bitmap bitmap, int newWidth, int newHeight)
scale Img
Bitmap resizeBmp = null;
if (bitmap == null) {
    return null;
if (newWidth <= 0 || newHeight <= 0) {
    throw new IllegalArgumentException("???????????????0");
int srcWidth = bitmap.getWidth();
...
BitmapscaleImg(File file, int newWidth, int newHeight)
scale Img
Bitmap resizeBmp = null;
if (newWidth <= 0 || newHeight <= 0) {
    throw new IllegalArgumentException("???????????????0");
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getPath(), opts);
int srcWidth = opts.outWidth;
...
BitmapgetScaleBitmap(Bitmap origialBitmap, int dstWidth, int dstHeight)
get Scale Bitmap
Bitmap scaleBitmap = Bitmap.createScaledBitmap(origialBitmap,
        dstWidth, dstHeight, true);
if (origialBitmap != null && !origialBitmap.isRecycled()) {
    origialBitmap.recycle();
return scaleBitmap;
BitmapgetScaleBitmap(Context context, int resId, int dstWidth, int dstHeight)
get Scale Bitmap
Bitmap origialBitmap = BitmapFactory.decodeResource(
        context.getResources(), resId);
Bitmap scaleBitmap = Bitmap.createScaledBitmap(origialBitmap,
        dstWidth, dstHeight, true);
if (origialBitmap != null && !origialBitmap.isRecycled()) {
    origialBitmap.recycle();
return scaleBitmap;
...
BitmapgetScaleImage(final Bitmap bitmap, final float boundBoxInDp)
get Scale Image
final int width = bitmap.getWidth();
final int height = bitmap.getHeight();
final float xScale = boundBoxInDp / width;
final float yScale = boundBoxInDp / height;
final float scale = xScale <= yScale ? xScale : yScale;
final Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
final Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0,
...
BitmapgenerateScaledBitmap(Bitmap bitmap, int width, int height)
Generates a bitmap scaled to provided width and height
if (bitmap != null) {
    try {
        return Bitmap.createScaledBitmap(bitmap, width, height,
                true);
    } catch (IllegalArgumentException illegalArgs) {
        return null;
} else {
...
BitmapgenerateScaledBitmap(Drawable drawable, int width, int height)
Generates a bitmap scaled to provided width and height
if (drawable != null && drawable instanceof BitmapDrawable) {
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    return generateScaledBitmap(bitmap, width, height);
} else {
    return null;
BitmapgenerateScaledBitmap(byte[] bitMapData, int width, int height)
Generates a bitmap scaled to provided width and height
if (bitMapData != null) {
    try {
        Bitmap bitmap = BitmapFactory.decodeByteArray(bitMapData,
                0, bitMapData.length);
        return generateScaledBitmap(bitmap, width, height);
    } catch (ArrayIndexOutOfBoundsException indexOutOfBounds) {
        return null;
    } catch (IllegalArgumentException illegalArgs) {
...