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(@Nullable DisplayMetrics display, @NonNull @ColorInt int colors[], 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 crop(Bitmap srcBmp, View canvasView, int downsampling) {
    float scale = 1f / downsampling;
    return Bitmap.createBitmap(srcBmp, (int) Math.floor((canvasView.getX()) * scale),
            (int) Math.floor((canvasView.getY()) * scale), (int) Math.floor((canvasView.getWidth()) * scale),
            (int) Math.floor((canvasView.getHeight()) * scale));
}

From source file:Main.java

public static Bitmap cropSquareBitmap(Bitmap srcBmp) {
    Bitmap dstBmp;//from  www . ja  v  a 2 s .co  m
    if (srcBmp.getWidth() >= srcBmp.getHeight()) {

        dstBmp = Bitmap.createBitmap(srcBmp, srcBmp.getWidth() / 2 - srcBmp.getHeight() / 2, 0,
                srcBmp.getHeight(), srcBmp.getHeight());

    } else {

        dstBmp = Bitmap.createBitmap(srcBmp, 0, srcBmp.getHeight() / 2 - srcBmp.getWidth() / 2,
                srcBmp.getWidth(), srcBmp.getWidth());
    }

    return dstBmp;
}

From source file:Main.java

public static Bitmap crop(Bitmap srcBmp, int side) {

    Bitmap dstBmp;//  ww  w.  j ava 2 s. com

    if (srcBmp.getWidth() >= srcBmp.getHeight()) {

        dstBmp = Bitmap.createBitmap(srcBmp, srcBmp.getWidth() / 2 - srcBmp.getHeight() / 2, 0,
                srcBmp.getHeight(), srcBmp.getHeight());

    } else {

        dstBmp = Bitmap.createBitmap(srcBmp, 0, srcBmp.getHeight() / 2 - srcBmp.getWidth() / 2,
                srcBmp.getWidth(), srcBmp.getWidth());
    }

    return Bitmap.createScaledBitmap(dstBmp, side, side, true);
}

From source file:Main.java

public static Bitmap resizeImageToHalf(Bitmap source) {
    int h = source.getHeight();
    int w = source.getWidth();
    return Bitmap.createBitmap(source, 0, 0, w, h);
}

From source file:Main.java

private static Bitmap createClippedBitmap(Bitmap bitmap, int x, int y, int width, int height) {
    if (bitmap == null) {
        return null;
    }//  w  w w.j  a v  a 2  s . co m

    Bitmap newBitmap = Bitmap.createBitmap(bitmap, x, y, width, height);

    return newBitmap;
}

From source file:Main.java

public static Bitmap cutBitmap(Bitmap bitmap, int nwidth, int nHeight) {
    if (null == bitmap || nwidth > bitmap.getWidth() || nHeight > bitmap.getHeight()) {
        return null;
    }/*from w w  w  .j  a v a2s.co  m*/
    Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, nwidth, nHeight);
    return result;
}

From source file:Main.java

private static Bitmap crop(Bitmap source) {
    int width = source.getWidth() - 2;
    int height = source.getHeight() - 2;
    if (width <= 0 || height <= 0) {
        return source;
    }//from   w w w. j a v  a2 s.  c  o  m
    return Bitmap.createBitmap(source, 1, 1, width, height);
}

From source file:Main.java

public static Bitmap cropCenter(Bitmap source, int targetWidth, int targetHeight) {
    int marginLeft = (source.getWidth() - targetWidth) / 2;
    int marginTop = (source.getHeight() - targetHeight) / 2;
    Bitmap newBitmap = Bitmap.createBitmap(source, marginLeft, marginTop, targetWidth, targetHeight);
    return newBitmap;
}

From source file:Main.java

public static Bitmap cutBitmap(Bitmap bitmap, int tagWidth, int tagHeight) {
    if (null == bitmap) {
        return null;
    }//from  w w  w . j a  v a 2 s .  co m
    Bitmap tmpBmp = Bitmap.createScaledBitmap(bitmap, tagWidth, tagHeight, false);
    return Bitmap.createBitmap(tmpBmp, 0, 0, tagWidth, tagHeight);
}

From source file:Main.java

static public Bitmap cropBitmap(Bitmap src, int x, int y, int width, int height, boolean isRecycle) {
    if (x == 0 && y == 0 && width == src.getWidth() && height == src.getHeight()) {
        return src;
    }/*w  ww .  ja  v a2  s .co m*/
    Bitmap dst = Bitmap.createBitmap(src, x, y, width, height);
    if (isRecycle && dst != src) {
        src.recycle();
    }
    return dst;
}