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 loadScaledBitmap(Context context, String bitmapFilePath, int widthDp, int heightDp)
        throws IOException {
    //create movie icon
    Bitmap bitmap;//from  w  w  w.  ja  va2s .  c  o m
    bitmap = BitmapFactory.decodeStream(context.openFileInput(bitmapFilePath));
    bitmap = Bitmap.createScaledBitmap(bitmap, widthDp, heightDp, true);
    return bitmap;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap photo, int newHeight, Context context) {
    final float densityMultiplier = context.getResources().getDisplayMetrics().density;
    int h = (int) (newHeight * densityMultiplier);
    int w = (int) (h * photo.getWidth() / ((double) photo.getHeight()));
    photo = Bitmap.createScaledBitmap(photo, w, h, true);
    return photo;
}

From source file:Main.java

public static Bitmap resizeBitmapToFitWidth(Bitmap bm, int width) {
    int oriWidth = bm.getWidth();
    int oriHeight = bm.getHeight();
    if (oriWidth < width) {
        return bm;
    } else {/*  w w w . j  a  v a2s .  c  om*/
        int height = (int) ((float) width / oriWidth * oriHeight);
        Bitmap tmp = Bitmap.createScaledBitmap(bm, width, height, false);
        bm.recycle();
        return tmp;
    }
}

From source file:Main.java

public static Bitmap scaleDownBitmap(Bitmap photo, int newHeight, Context context) {

    final float densityMultiplier = context.getResources().getDisplayMetrics().density;

    int h = (int) (newHeight * densityMultiplier);
    int w = (int) (h * photo.getWidth() / ((double) photo.getHeight()));

    photo = Bitmap.createScaledBitmap(photo, w, h, true);

    return photo;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap originalBitmap, int toWidth, int toHeight) {

    int image_width = originalBitmap.getWidth();
    int image_height = originalBitmap.getHeight();

    float scale = (float) toWidth / (float) image_width;

    if (image_width < image_height) {
        scale = toHeight / image_height;
    }/*from ww  w .j  a v  a 2 s .co m*/

    return Bitmap.createScaledBitmap(originalBitmap, (int) (image_width * scale), (int) (image_height * scale),
            true);

}

From source file:Main.java

public static Bitmap resize(Bitmap bitmap, int width, int height) {
    Log.e("bmhelper", width + "  " + height);
    return Bitmap.createScaledBitmap(bitmap, width, height, true);
}

From source file:Main.java

public static Bitmap CompressBitmap(Bitmap image) {
    int width = image.getWidth();
    int height = image.getHeight();
    float scale = 500.0f / height;
    if (width > 500 || height > 500) {
        width = Math.round(width * scale);
        height = Math.round(height * scale);
    }/*from   w  w w  . ja  v  a 2 s  .  c  om*/
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    return scaledBitmap;
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap image, int maxSize) {
    if (image == null)
        return null;

    int width = image.getWidth();
    int height = image.getHeight();

    float bitmapRatio = (float) width / (float) height;

    width = maxSize;//from   w w  w.  j  a va2  s. c o  m
    height = (int) (width / bitmapRatio);

    return Bitmap.createScaledBitmap(image, width, height, true);
}

From source file:Main.java

public static Bitmap resizeOuterFit(Bitmap src, Rect rect) {

    float aspectRatio = Math.max((float) rect.width() / src.getWidth(),
            (float) rect.height() / src.getHeight());
    int newWidth = (int) (src.getWidth() * aspectRatio);
    int newHeight = (int) (src.getHeight() * aspectRatio);
    return Bitmap.createScaledBitmap(src, newWidth, newHeight, false);
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap src, int width, int height) {
    return Bitmap.createScaledBitmap(src, width, height, true);
}