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 zoomBitmap(Bitmap source, float w, float h) {
    int height = source.getHeight();
    int width = source.getWidth();
    Matrix matrix = new Matrix();
    matrix.postScale(w / width, h / height);
    Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
    return bitmap;
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale((float) width / w, (float) height / h);
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
}

From source file:Main.java

public static Bitmap rotateBitmapDegree(Bitmap bm, int degree) {
    Bitmap returnBm;//from   w ww  . j  a v a2 s .  c  o  m
    int w = bm.getWidth();
    int h = bm.getHeight();

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

    returnBm = Bitmap.createBitmap(bm, 0, 0, w, h, matrix, true);

    if (bm != returnBm) {
        bm.recycle();
    }

    return returnBm;
}

From source file:Main.java

public static Bitmap getRotateBitmap(Bitmap bitmap, int rotation) {
    if (null == bitmap || bitmap.isRecycled()) {
        return null;
    }//from  w  w w  .  j  a va 2s.  c om

    Matrix matrix = new Matrix();
    matrix.postRotate(rotation);
    Bitmap cropBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
    return cropBitmap;
}

From source file:Main.java

public static Bitmap getRotatedBitmap(Bitmap mBitmap, float degrees) {
    int width = mBitmap.getWidth();
    int height = mBitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(degrees);//from   w ww  .j ava 2 s  .c  o m
    Bitmap mRotateBitmap = Bitmap.createBitmap(mBitmap, 0, 0, width, height, matrix, true);

    return mRotateBitmap;
}

From source file:Main.java

public static Bitmap getFixedBitmap(Bitmap bm, int w, int h, boolean filter) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale((float) w / width, (float) h / height);
    return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, filter);
}

From source file:Main.java

public static Bitmap createRotatedBitmap(Bitmap bm, float degree) {
    Bitmap bitmap = null;/* w w w .ja v a 2 s  .co m*/
    if (degree != 0) {
        Matrix matrix = new Matrix();
        matrix.preRotate(degree);
        bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
    }

    return bitmap;
}

From source file:Main.java

private static Bitmap createScaledBitmap(Bitmap bitmap, float scale, int width, int height) {
    if (bitmap == null) {
        return null;
    }/*  w ww. j a  va2  s.com*/

    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);

    Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

    return scaledBitmap;
}

From source file:Main.java

public static Bitmap PicZoom(Bitmap bmp, int width, int height) {
    int bmpWidth = bmp.getWidth();
    int bmpHeght = bmp.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale((float) width / bmpWidth, (float) height / bmpHeght);
    return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeght, matrix, true);
}

From source file:Main.java

public static Bitmap rotation90(Bitmap bitmap) {
    if (bitmap == null)
        return null;
    if (bitmap.isRecycled())
        return null;
    Bitmap bmp = null;/*  ww w  . jav  a 2 s. co  m*/
    Matrix matrix = new Matrix();
    matrix.postRotate(90);
    bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
    bitmap.recycle();
    return bmp;
}