Example usage for android.graphics Canvas Canvas

List of usage examples for android.graphics Canvas Canvas

Introduction

In this page you can find the example usage for android.graphics Canvas Canvas.

Prototype

@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public Canvas(long nativeCanvas) 

Source Link

Usage

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);/*from w w  w.jav  a2 s  .c o  m*/
    canvas.drawBitmap(fg, left, top, null);

    return result;
}

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  w w  . j a v a2  s. c o m*/
    paint.setAntiAlias(true);
    canvas.drawBitmap(bmp, bmp.getWidth(), bmp.getHeight(), paint);
    return b;
}

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 overlayToDownCenter(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);
    Matrix matrix = new Matrix();
    matrix.setTranslate(((float) bmp1.getWidth() - bmp2.getWidth()) / 2, bmp1.getHeight() - bmp2.getHeight());
    canvas.drawBitmap(bmp2, matrix, null);
    return bmOverlay;
}

From source file:Main.java

public static Bitmap convertBitmap(Drawable drawable, int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);/*from   ww  w  . ja  v a2 s .c  o  m*/
    return bitmap;
}

From source file:Main.java

public static Bitmap scale(Bitmap b, float scale) {
    Bitmap res = Bitmap.createBitmap((int) (b.getWidth() * scale + .5f), (int) (b.getHeight() * scale + .5f),
            b.getConfig());/* w w  w  .  j a  v  a2 s.  c  o m*/
    Canvas c = new Canvas(res);
    c.scale(scale, scale);
    c.drawBitmap(b, 0, 0, scalePaint);
    return res;
}

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);/*from w w  w .  ja v  a  2  s. c o m*/

    return bitmap;
}

From source file:Main.java

public static Bitmap overlayToDownRightCorner(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);
    Matrix matrix = new Matrix();
    matrix.setTranslate(bmp1.getWidth() - bmp2.getWidth(), bmp1.getHeight() - bmp2.getHeight());
    canvas.drawBitmap(bmp2, matrix, null);
    return bmOverlay;
}

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  w  w .j av  a  2 s .  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 convertViewToBitmapWithCanvas(View view, int bitmapWidth, int bitmapHeight) {
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
    view.draw(new Canvas(bitmap));
    return bitmap;
}