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

static public Bitmap scaleBitmap(Bitmap bitmap, float scaleX, float scaleY) {
    Matrix matrix = new Matrix();
    matrix.postScale(scaleX, scaleY);//from  w w w.  j  a  v  a 2 s  .  c  o  m
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

/**
 * Expand the bitmap to the specified scale.
 *
 * @param bitmap to expand.//  w  w w. j  a  v a 2s.  c o  m
 * @param scale  the expand scale, must be > 1.0.
 * @return the expanded bitmap.
 */
public static Bitmap expand(Bitmap bitmap, float scale) {
    if (scale <= 1.0f) {
        return bitmap.copy(bitmap.getConfig(), false);
    }

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

    return Bitmap.createBitmap(bitmap, 0, 0, (int) (scale * bitmap.getWidth()),
            (int) (scale * bitmap.getHeight()), matrix, true);
}

From source file:Main.java

public static Bitmap createResizedBitmap(Bitmap srcBit, int newWidth, int newHeight) {
    int width = srcBit.getWidth();
    int height = srcBit.getHeight();

    // calculate the scale - in this case = 0.4f
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(srcBit, 0, 0, width, height, matrix, true);

    width = resizedBitmap.getWidth();/*from  w w w  .  j  av a 2  s. c  o  m*/
    height = resizedBitmap.getHeight();

    Log.i("ImageResize",
            "Image Resize Result : " + Boolean.toString((newHeight == height) && (newWidth == width)));
    return resizedBitmap;
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float w, float h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float scaleW = ((float) w / width);
    float scaleH = ((float) h / height);
    matrix.postScale(scaleW, scaleH);//from   ww  w  . ja  va2 s  . c  o m
    Bitmap newBmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

    return newBmp;
}

From source file:Main.java

public static Bitmap rotate(Bitmap bitmap, int degrees) {
    Matrix matrix = new Matrix();
    matrix.postRotate(degrees);/* w w w. j  a  va  2 s  . c  o m*/
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

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();
    float scaleWidth = ((float) width / w);
    float scaleHeight = ((float) height / h);
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
    return newbmp;
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
    Bitmap newbmp = null;/*from   w  w w  . ja  va  2s  . com*/
    if (bitmap != null) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Matrix matrix = new Matrix();
        float scaleWidht = ((float) w / width);
        float scaleHeight = ((float) h / height);
        matrix.postScale(scaleWidht, scaleHeight);
        try {
            newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
        } catch (Exception e) {
            newbmp = bitmap;
        }
    }
    return newbmp;
}

From source file:Main.java

/**
 * Rotate the image//from   www .ja  v  a2 s. c om
 * @param bm source bitmap
 * @param rotation degree of rotation
 * @return return the rotated bitmap
 */
public static Bitmap rotateImage(Bitmap bm, int rotation) {
    Matrix matrix = new Matrix();
    matrix.postRotate(rotation);
    return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
}