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 rotateBitmap(Bitmap bitmap, int rotationAngle) {
    mMatrix.reset();//from  w ww . j  av  a2  s.  co  m
    mMatrix.postRotate(rotationAngle);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mMatrix, false);
}

From source file:Main.java

/**
 * TODO doc/* w  ww.  j  a v  a 2  s  .  c  om*/
 *
 * @param source
 * @return
 */
public static Bitmap flipVerticallyBitmap(Bitmap source) {
    Matrix m = new Matrix();
    m.preScale(1, -1);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, false);
}

From source file:Main.java

public static Bitmap rotateBitmapDegrees(Bitmap bitmap, int orientation) {
    if (orientation == 0) {
        return bitmap;
    }/*from  w  w w  . jav a  2  s  .co  m*/

    Matrix matrix = new Matrix();
    matrix.setRotate(orientation);
    Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    bitmap.recycle();
    return bmRotated;
}

From source file:Main.java

/**
 * TODO doc// w  ww .j av  a 2  s .  c o m
 *
 * @param source
 * @return
 */
public static Bitmap flipHorizonallyBitmap(Bitmap source) {
    Matrix m = new Matrix();
    m.setScale(-1, 1);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, false);
}

From source file:Main.java

public static Bitmap scaleExistingBitmap(Bitmap bm, float scaleWidth, float scaleHeight) {

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

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);

    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}

From source file:Main.java

public static Bitmap postRotateBitamp(Bitmap bmp, float degree) {

    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(degree);//from   w w w .j av  a  2s .c  om
    Bitmap resizeBmp = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true);
    return resizeBmp;
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bitmap, float degrees) {
    Bitmap resizeBmp = null;/*from  w w  w. j ava2 s .  c om*/
    if (bitmap != null && degrees > 0) {
        Matrix matrix = new Matrix();
        matrix.setRotate(degrees);
        resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }
    return resizeBmp;
}

From source file:Main.java

public static Bitmap rotate(Bitmap bitmap, int degree) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Matrix mtx = new Matrix();
    mtx.postRotate(degree);//  w  w w. j  a v a  2s  . co m
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}

From source file:Main.java

public static Bitmap rotate(@NonNull final Bitmap bitmap, final float angle) {
    final Matrix matrix = new Matrix();
    matrix.postRotate(angle);//from  w  w w  . j av a2s  .  co m
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap resize(Bitmap bmp, int width, int height) {
    float sx = (width * 1.0f) / bmp.getWidth();
    float sy = (height * 1.0f) / bmp.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(sx, sy);//from w  w w.j  a va 2  s . c  om
    return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}