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 rotateImage(Bitmap bitmap, int rotate) {
    if (rotate != 0) {
        // rotate
        Matrix m = new Matrix();
        m.postRotate(rotate);//from w w  w  .  j av  a 2  s  . c  om
        Bitmap rotImage = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
        bitmap.recycle();
        System.gc();

        return rotImage;
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap roateImage(Bitmap mBitmap, float degree) {
    if (mBitmap.getWidth() > mBitmap.getHeight()) {
        Matrix matrix = new Matrix();
        matrix.postRotate(degree);//  w  ww. j  a v a 2  s  .  c o  m
        mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
    }
    return mBitmap;
}

From source file:Main.java

private static Bitmap getBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.setScale(0.5f, 0.5f);// w w w.  j  av a2  s .  co m
    bitmap = Bitmap.createBitmap(bitmap, width / 2 - 10, height / 3 - 10, width / 2 + 10, height / 3 + 10,
            matrix, true);
    return bitmap;
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bmp, float rotation) {
    if (rotation == 0) {
        return bmp;
    }/* w ww .  j a v a 2  s.  c  o m*/

    Matrix matrix = new Matrix();
    matrix.postRotate(rotation);

    return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bitmap, float sx, float sy) {
    Bitmap newBitmap;//from   w  ww  . j av  a2 s .  c  om
    Matrix matrix = new Matrix();
    matrix.postScale(sx, sy);
    newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
    return newBitmap;
}

From source file:Main.java

private static Bitmap rotate(Bitmap bmp, int rotation) {
    if (rotation == 0)
        return bmp;

    try {/*from w  ww . j av  a  2 s  . co m*/
        Matrix matrix = new Matrix();
        matrix.preRotate(rotation);
        return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    } finally {
        bmp.recycle();
    }
}

From source file:Main.java

public static Bitmap showPicture(Bitmap myBitmap, int rot) {
    Matrix matrix = new Matrix();
    matrix.postRotate(rot);//  ww  w  . j av  a 2  s .  c o m

    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

/**
 *
 * @param source/*  ww w . j a v a2s. c o m*/
 * @param angle
 * @return
 */
private static Bitmap rotateImage(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap decodeBitmap(Bitmap bitmap, int orientation) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix mtx = new Matrix();
    mtx.postRotate(orientation);//  ww w .  j a  va  2  s.com
    return Bitmap.createBitmap(bitmap, 0, 0, width, height, mtx, true);
}

From source file:Main.java

public static Bitmap big(Bitmap bitmap, float scale) {
    if (bitmap == null) {
        return null;
    }/*from ww w .j a  va 2 s  .  c o  m*/
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);
    Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    if (!bitmap.isRecycled()) {
        bitmap.recycle();
    }
    return resizeBmp;
}