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 rotate) {
    if (bitmap == null)
        return null;

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    // Setting post rotate to 90
    Matrix mtx = new Matrix();
    mtx.postRotate(rotate);/*from w  w  w.  j av  a 2  s .  c o  m*/
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}

From source file:Main.java

private static Bitmap rotateBitmap(Bitmap bitmap, int rotate) {
    if (bitmap == null)
        return null;

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    // Setting post rotate to 90  
    Matrix mtx = new Matrix();
    mtx.postRotate(rotate);/*  w w w.  ja  va2s. co  m*/
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}

From source file:Main.java

public synchronized static Bitmap getRotatedBitmap(Bitmap bitmap, int degrees) {
    if (degrees != 0 && bitmap != null) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
        try {//from  w w w.j a  v  a2  s.  c o m
            Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
            if (bitmap != b2) {
                bitmap.recycle();
                bitmap = b2;
            }
        } catch (OutOfMemoryError e) {
            // Log.d(PhotoUtil.class.getSimpleName(),
            // "Error: "+e.getMessage());
        }
    }

    return bitmap;
}

From source file:Main.java

private static Bitmap getScaleLogo(Bitmap logo, int w, int h) {
    if (logo == null)
        return null;
    Matrix matrix = new Matrix();
    float scaleFactor = Math.min(w * 1.0f / 5 / logo.getWidth(), h * 1.0f / 5 / logo.getHeight());
    matrix.postScale(scaleFactor, scaleFactor);
    Bitmap result = Bitmap.createBitmap(logo, 0, 0, logo.getWidth(), logo.getHeight(), matrix, true);
    return result;
}

From source file:Main.java

/**
 * Rotate the bitmap with the specif angle
 *
 * @param angle//from  w  w w.  ja  va 2  s .  c  om
 * @param bitmap
 * @return Bitmap
 */
public static Bitmap rotateImageView(int angle, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    System.out.println("angle2=" + angle);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap rotateBitmap(int degrees, Bitmap bitmap) {
    if (degrees == 0 || null == bitmap) {
        return bitmap;
    }//from   ww w . j a v  a2s.c  om
    Matrix matrix = new Matrix();
    matrix.setRotate(degrees, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
    Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    if (null != bitmap) {
        bitmap.recycle();
        bitmap = null;
    }
    return bmp;
}

From source file:Main.java

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

From source file:Main.java

public static Bitmap zoomBitmapScale(Bitmap bitmap, float sx, float sy) {
    if (sx <= 0 || sy <= 0) {
        return bitmap;
    }/*  w w  w .jav a2s. co m*/
    if (bitmap == null) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.postScale(sx, sx);
    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 scaleWidht = (float) width / w;
    float scaleHeight = (float) height / h;
    matrix.postScale(scaleWidht, scaleHeight);
    return Bitmap.createBitmap(bitmap, 0, 0, width, height, 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);
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
}