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(int width, int height, @NonNull Config config) 

Source Link

Document

Returns a mutable bitmap with the specified width and height.

Usage

From source file:Main.java

public static Bitmap loadBitmapFromView(View v) {
    Bitmap b = Bitmap.createBitmap(v.getLayoutParams().width, v.getLayoutParams().height,
            Bitmap.Config.ARGB_8888);/*from w  ww .  j  ava2s .  c  o m*/
    Canvas c = new Canvas(b);
    v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
    v.draw(c);
    return b;
}

From source file:Main.java

public static Bitmap createViewBitmap(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);/*from   w  ww .j a va  2s  . c  om*/
    return bitmap;
}

From source file:Main.java

public static Bitmap compoundBitmap(Bitmap bg, Bitmap fg, int left, int top) {
    Bitmap result = Bitmap.createBitmap(bg.getWidth(), bg.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(bg, 0, 0, null);// w ww .j a  v  a2s  .  c o  m
    canvas.drawBitmap(fg, left, top, null);

    return result;
}

From source file:Main.java

public static Bitmap createBitmapFromColor(int color, int width, int height) {
    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    bmp.eraseColor(color);/*from w  w  w .ja v  a2  s.com*/
    return bmp;
}

From source file:Main.java

public static Bitmap captureView(View view, int j, int k) {
    Bitmap bitmap = Bitmap.createBitmap(j, k, android.graphics.Bitmap.Config.ARGB_8888);
    view.draw(new Canvas(bitmap));
    return bitmap;
}

From source file:Main.java

public static Bitmap changeBitmapColor(Bitmap bmp, int color) {
    Bitmap b = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
    Canvas canvas = new Canvas(b);
    Paint paint = new Paint();
    paint.setColor(color);/*from w  ww . java 2s  .  co  m*/
    paint.setAntiAlias(true);
    canvas.drawBitmap(bmp, bmp.getWidth(), bmp.getHeight(), paint);
    return b;
}

From source file:Main.java

public static Bitmap DrawToBitmap(Drawable dw) {
    Bitmap bitmap = Bitmap.createBitmap(dw.getMinimumWidth(), dw.getMinimumHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    dw.setBounds(0, 0, dw.getMinimumWidth(), dw.getMinimumHeight());
    dw.draw(canvas);//  w  w w. j  a v a 2s . c  om

    return bitmap;
}

From source file:Main.java

public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    canvas.drawBitmap(bmp2, 0, 0, null);
    return bmOverlay;
}

From source file:Main.java

public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
    Bitmap bitmap = null;/* w w  w .  j  a  v  a  2 s . co  m*/
    try {
        bitmap = Bitmap.createBitmap(width, height, config);
    } catch (OutOfMemoryError e) {
        while (bitmap == null) {
            System.gc();
            System.runFinalization();
            bitmap = createBitmap(width, height, config);
        }
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap createPlaceholderBitmap(int width, int height) {
    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    Bitmap placeholderBitmap = Bitmap.createBitmap(width, height, config);
    placeholderBitmap.eraseColor(android.graphics.Color.DKGRAY);
    return placeholderBitmap;
}