Android Utililty Methods Canvas Draw

List of utility methods to do Canvas Draw

Description

The list of methods to do Canvas Draw are organized into topic(s).

Method

voiddrawCross(Bitmap bm, int x, int y)
draw Cross
Canvas c = new Canvas(bm);
Paint p = new Paint();
p.setColor(0xffff0000);
c.drawLine(x - 4, y, x + 4, y, p);
c.drawLine(x, y - 4, x, y + 4, p);
voiddrawSelect(Bitmap bm, int x, int y, int cellWidth, int cellHeight)
draw Select
Canvas canvas = new Canvas(bm);
canvas.drawColor(Color.TRANSPARENT,
        android.graphics.PorterDuff.Mode.CLEAR);
Paint paint = new Paint();
paint.setARGB(255, 255, 0, 0);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(3f);
canvas.drawRect(new Rect((x - 1) * cellWidth, (y - 1) * cellHeight,
...
voiddrawText(String strMsg, Canvas g, Paint paint, int setx, int sety, int fg, int bg)
draw Text
paint.setColor(bg);
g.drawText(strMsg, setx + 1, sety, paint);
g.drawText(strMsg, setx, sety - 1, paint);
g.drawText(strMsg, setx, sety + 1, paint);
g.drawText(strMsg, setx - 1, sety, paint);
paint.setColor(fg);
g.drawText(strMsg, setx, sety, paint);
g.restore();
...
voiddrawTextAtCanvasCenter(Canvas canvas, Paint paint, String text)
draw Text At Canvas Center
if (text == null) {
    return;
final int width = canvas.getWidth();
final int height = canvas.getHeight();
int offsetX, offsetY;
offsetX = calcXWhenAlignCenter(width, paint, text);
offsetY = calcYWhenAlignCenter(height, paint);
...
voidcircle(Canvas canvas, int color, int stroke, float x, float y, float radius)
circle
Paint paint = new Paint();
paint.setColor(color);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(stroke);
canvas.drawCircle(x, y, radius, paint);
voidrect(Canvas canvas, int color, int stroke, float x, float y, float width, float height)
rect
Paint paint = new Paint();
paint.setColor(color);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(stroke);
float leftx = x;
float topy = y;
float rightx = x + width;
float bottomy = y + height;
...
Bitmapadd(Bitmap firstlayer, Bitmap secondlayer)
combines to Bitmap s
Bitmap data = Bitmap.createBitmap(secondlayer.getWidth(),
        secondlayer.getHeight(), secondlayer.getConfig());
Canvas temp = new Canvas(data);
temp.drawBitmap(secondlayer, 0, 0, null);
temp.drawBitmap(firstlayer, 0, 0, null);
return data;
Bitmapadd(Bitmap[] images)
combines to Bitmap s
Bitmap data = Bitmap.createBitmap(images[0].getWidth(),
        images[0].getHeight(), images[0].getConfig());
Canvas temp = new Canvas(data);
for (int i = 0; i < images.length; i++) {
    temp.drawBitmap(images[i], 0, 0, null);
return data;