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 getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    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 orientationBitMap(String filepath, Bitmap bit) {
    int orientation = getExifOrientation(filepath);
    if (orientation != 0) {
        Matrix matrix = new Matrix();
        matrix.setRotate(orientation);//from w  w  w . j ava  2s .  c  o m
        return Bitmap.createBitmap(bit, 0, 0, bit.getWidth(), bit.getHeight(), matrix, true);
    }
    return bit;
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bitmap, int maxLength) {
    if (null == bitmap)
        return null;
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    float scale = (float) maxLength / h;
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);//from w  w  w  .j  ava  2s . c o m
    Bitmap zoomedBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
    return zoomedBitmap;
}

From source file:Main.java

public static Bitmap getRotatedBitmap(Bitmap imageBitmap, int screenRotation) {
    int rotationAdjustment = getRotationAdjustment(screenRotation);
    Matrix matrix = new Matrix();
    matrix.postRotate(rotationAdjustment);
    return Bitmap.createBitmap(imageBitmap, 0, 0, imageBitmap.getWidth(), imageBitmap.getHeight(), matrix,
            true);/*from  w w  w . jav a2s.  co m*/
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float sx, float sy) {
    Matrix matrix = new Matrix();
    matrix.postScale(sx, sy);//from   w w w .j  a v  a2 s .  co m
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bm, float newWidth, float newHeight) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = newWidth / width;
    float scaleHeight = newHeight / height;

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

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

From source file:Main.java

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

    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

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

    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return resizedBitmap;
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
    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);
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newbmp;
}

From source file:Main.java

public static Bitmap zoomBitmapSize(Bitmap bitmap, float width, float height) {
    if (width <= 0 || height <= 0) {
        return bitmap;
    }//w  w  w.  j a v a2s.  c  om
    if (bitmap == null) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.postScale(width / bitmap.getWidth(), height / bitmap.getHeight());
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

/**
 * Method to rotate a Bitmap specifying the angle.
 *
 * @param source The original Bitmap.//from w  w w. j  a v a 2s  . c  o m
 * @param angle  float that represents the rotation angle.
 * @return The rotated Bitmap.
 */
public static Bitmap rotate(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}