Example usage for android.graphics Bitmap createBitmap

List of usage examples for android.graphics Bitmap createBitmap

Introduction

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

Prototype

public static Bitmap createBitmap(@NonNull DisplayMetrics display, @NonNull @ColorInt int[] colors, int offset,
        int stride, int width, int height, @NonNull Config config) 

Source Link

Document

Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.

Usage

From source file:Main.java

public static Bitmap rotateFromDegree(Bitmap bitmap, int degree) {
    if (bitmap == null || degree == 0)
        return bitmap;
    Matrix matrix = new Matrix();
    matrix.preRotate(degree);//  w w w  .j av a 2 s  .  c o m
    Bitmap mBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    return mBitmap;
}

From source file:Main.java

public static Bitmap compressBitmap(Bitmap bitmap, int compressFactor) {
    Matrix matrix = new Matrix();
    matrix.postScale(1.0f / compressFactor, 1.0f / compressFactor);
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    return bitmap;
}

From source file:Main.java

public static Bitmap GetMirror(Bitmap bm) {
    if (bm == null)
        return null;

    float[] mirrorM = { -1, 0, 0, 0, 1, 0, 0, 0, 1 };

    Matrix m = new Matrix();
    m.setValues(mirrorM);/*from   w w  w .j av a  2 s  . c om*/
    return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, false);
}

From source file:Main.java

public static Bitmap zoom(Bitmap source, float wf, float hf) {
    Matrix matrix = new Matrix();
    float sx = wf / source.getWidth();
    float sy = hf / source.getHeight();
    matrix.postScale(sx, sy);/*ww w. j av a  2  s .c o m*/
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap b, float rotateDegree) {
    if (b == null) {
        return null;
    }/*  w  w  w .j av a 2s . c  om*/
    Matrix matrix = new Matrix();
    matrix.postRotate(rotateDegree);
    Bitmap rotaBitmap = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
    return rotaBitmap;
}

From source file:Main.java

public static Bitmap smallBitmap(Bitmap bitmap, float scale) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/*w  w w .  j  a  v a2  s .  c o  m*/
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
    return newbmp;
}

From source file:Main.java

public static Bitmap scaleBitmapSoft(Bitmap temp, float scaleSize) {
    if (!canUse(temp)) {
        return null;
    }//from  w w  w  .ja v a 2  s .  co m
    Matrix m = new Matrix();
    m.postScale(scaleSize, scaleSize, 0, 0);
    return Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), m, true);
}

From source file:Main.java

public static Bitmap rotateImageView(int angle, Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }//from  w  w w . ja v a2s . c o  m
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
            true);
    return resizedBitmap;
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bmp, int degrees) {
    if (degrees != 0) {
        Matrix matrix = new Matrix();
        matrix.postRotate(degrees % 360);
        return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    }/*ww  w .j  a  va 2s  .  c om*/
    return bmp;
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float scale) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/*from   ww w  .  j a v a2  s  .c  o m*/
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newbmp;
}