Example usage for android.graphics Bitmap createScaledBitmap

List of usage examples for android.graphics Bitmap createScaledBitmap

Introduction

In this page you can find the example usage for android.graphics Bitmap createScaledBitmap.

Prototype

public static Bitmap createScaledBitmap(@NonNull Bitmap src, int dstWidth, int dstHeight, boolean filter) 

Source Link

Document

Creates a new bitmap, scaled from an existing bitmap, when possible.

Usage

From source file:Main.java

public static Bitmap showPicture(Bitmap myBitmap, int rot) {
    Matrix matrix = new Matrix();
    matrix.postRotate(rot);/*from  ww w  .  jav a 2  s.  c om*/

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, 320, 320, true);
    return Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix,
            true);
}

From source file:Main.java

public static Bitmap getFullScreenBitmap(Bitmap bitmap, int wScale, int hScale) {
    int dstWidth = bitmap.getWidth() * wScale;
    int dstHeight = bitmap.getHeight() * hScale;
    Bitmap result = Bitmap.createScaledBitmap(bitmap, dstWidth, dstHeight, false);
    return result;
}

From source file:Main.java

private static Bitmap createScaledBitMap(Bitmap src, int destWidth, int destHeight) {
    // TODO Auto-generated method stub
    if (src == null) {
        return null;
    }/* w w  w .j ava 2  s.  co  m*/
    Bitmap dest = Bitmap.createScaledBitmap(src, destWidth, destHeight, false);
    if (dest != src) {
        src.recycle();
    }
    return dest;
}

From source file:Main.java

public static Bitmap scaleToFitWidth(Bitmap b, int width) {
    if (b == null)
        return null;
    if (b.getWidth() <= width)
        return b;

    float factor = width / (float) b.getWidth();
    return Bitmap.createScaledBitmap(b, width, (int) (b.getHeight() * factor), true);
}

From source file:Main.java

public static Bitmap getScaleBitmap(Bitmap srcBitmap, int outHeightSimple, Context context) {
    int outHeight = (int) (outHeightSimple * context.getResources().getDisplayMetrics().density);
    return Bitmap.createScaledBitmap(srcBitmap, srcBitmap.getWidth() * outHeight / srcBitmap.getHeight(),
            outHeight, true);/* w  ww. jav a 2s .  c o m*/
}

From source file:Main.java

public static Bitmap zoomImage(Resources res, int resID, int newWidth, int newHeight) {
    Bitmap map = BitmapFactory.decodeResource(res, resID);
    return Bitmap.createScaledBitmap(map, newWidth, newHeight, false);
}

From source file:Main.java

public static Bitmap scaleBitmapByFactor(Bitmap source, float factor) {
    int newWidth = (int) (source.getWidth() * factor);
    int newHeight = (int) (source.getHeight() * factor);
    return Bitmap.createScaledBitmap(source, newWidth, newHeight, true);
}

From source file:Main.java

public static Bitmap getImageThumbnail(Bitmap input) {
    int desiredWidth = 500;
    Float width = new Float(input.getWidth());
    Float height = new Float(input.getHeight());
    Float ratio = width / height;
    return Bitmap.createScaledBitmap(input, (int) (desiredWidth * ratio), desiredWidth, false);
}

From source file:Main.java

public static Bitmap scaleToStretchBitmap(Bitmap dst, InputStream is) {
    Bitmap src = BitmapFactory.decodeStream(is);

    return Bitmap.createScaledBitmap(src, dst.getWidth(), dst.getHeight(), true);
}

From source file:Main.java

public static Drawable resizeToIcon(final Bitmap bitmap, final int width, final int height) {
    final Bitmap b = Bitmap.createScaledBitmap(bitmap, width, height, true);
    final Drawable d = new BitmapDrawable(Resources.getSystem(), b);
    return d;/*from  ww  w  .  j  av a 2s  .c o  m*/
}