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 final Bitmap scaleToHeight(Bitmap bitmap, int height) {
    int width = height * bitmap.getWidth() / bitmap.getHeight();
    return Bitmap.createScaledBitmap(bitmap, width, height, true);
}

From source file:Main.java

public static Bitmap getScaleBitmap(Bitmap srcBmp, int width, int height) {
    Bitmap bitmap = null;/*from w ww .j av  a  2s  .c  om*/
    try {
        bitmap = Bitmap.createScaledBitmap(srcBmp, width, height, false);
        // recycleBitmap(srcBmp);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap getScaledBitmp(@NonNull Bitmap originBitmap, int targetWidth, int targetHeight) {

    return Bitmap.createScaledBitmap(originBitmap, targetWidth, targetHeight, true);

}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bitmap) {
    int width = 300; // - Dimension in pixels
    int height = 300; // - Dimension in pixels
    return Bitmap.createScaledBitmap(bitmap, width, height, false);
}

From source file:Main.java

public static Bitmap cutBitmap(Bitmap bitmap, int tagWidth, int tagHeight) {
    if (null == bitmap) {
        return null;
    }/* ww w  . j  a  va 2  s.c  o  m*/
    Bitmap tmpBmp = Bitmap.createScaledBitmap(bitmap, tagWidth, tagHeight, false);
    return Bitmap.createBitmap(tmpBmp, 0, 0, tagWidth, tagHeight);
}

From source file:Main.java

public static String getHash(Bitmap bitmap) {
    Bitmap temp = Bitmap.createScaledBitmap(bitmap, 8, 8, false);
    int[] grayValues = reduceColor(temp);
    int average = sum / grayValues.length;
    String reslut = computeBits(grayValues, average);
    return reslut;
}

From source file:Main.java

public static int getDominantColor(Bitmap bitmap) {
    try {/*w  w  w.  j  av a2 s.  c o  m*/
        Bitmap onePixelBitmap = Bitmap.createScaledBitmap(bitmap, 1, 1, true);
        return onePixelBitmap.getPixel(0, 0);
    } catch (Exception ex) {
        return Color.BLACK;
    }
}

From source file:Main.java

static public Bitmap strechToFill(Bitmap b, int width, int height) {
    float factorH = height / (float) b.getHeight();
    float factorW = width / (float) b.getWidth();
    return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorW), (int) (b.getHeight() * factorH), false);
}

From source file:Main.java

static public Bitmap strechToFill(Bitmap b, int width, int height) {
    float factorH = height / (float) b.getHeight();
    float factorW = width / (float) b.getWidth();
    return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorW), (int) (b.getHeight() * factorH), true);
}

From source file:Main.java

static public Bitmap scaleToFitHeight(Bitmap b, int height) {
    Log.e("Hieght", height + "");
    float factor = height / (float) b.getHeight();

    return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factor), height, false);

}