Example usage for android.graphics Paint Paint

List of usage examples for android.graphics Paint Paint

Introduction

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

Prototype

public Paint(Paint paint) 

Source Link

Document

Create a new paint, initialized with the attributes in the specified paint parameter.

Usage

From source file:Main.java

public static int measureTextHeight(int textsize) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textsize);/* w  ww.j a v  a 2  s  . c om*/
    Paint.FontMetrics metrics = paint.getFontMetrics();
    return (int) Math.ceil(metrics.descent - metrics.ascent);
}

From source file:Main.java

public static int measureTextWidth(String text, int textsize) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textsize);/*  www . j  a  va2 s  . c  o  m*/
    return (int) paint.measureText(text);
}

From source file:Main.java

public static Paint getUIPainter() {
    Paint uiPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    uiPaint.setColor(Color.argb(128, 255, 255, 255));
    uiPaint.setStyle(Style.STROKE);
    uiPaint.setStrokeWidth((float) 3.0);
    return uiPaint;
}

From source file:Main.java

public static Rect getTextBounds(float textSize, String text) {
    Rect bounds = new Rect();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textSize);// w ww  . j ava  2 s  .  c o m

    paint.getTextBounds(text, 0, text.length(), bounds);

    bounds.height();
    return bounds;
}

From source file:Main.java

@NonNull
static Paint createPaint(int color) {
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(STROKE);/*  www.j  a  v a  2s . c  o  m*/
    paint.setColor(color);
    return paint;
}

From source file:Main.java

/**
 *
 * @return//from  w  w w  . j a  v a 2  s .c o  m
 */
public static Paint newPaint() {
    Paint paint = new Paint(1);
    paint.setFilterBitmap(true);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    return paint;
}

From source file:Main.java

public static Bitmap combineTwoBitmaps(Bitmap background, Bitmap foreground) {
    Bitmap combinedBitmap = Bitmap.createBitmap(background.getWidth(), background.getHeight(),
            background.getConfig());/*from  w ww. ja va  2 s.  c  o  m*/
    Canvas canvas = new Canvas(combinedBitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(background, 0, 0, paint);
    canvas.drawBitmap(foreground, 0, 0, paint);
    return combinedBitmap;
}

From source file:Main.java

public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) {
    android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
    // set default bitmap config if none
    if (bitmapConfig == null) {
        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }//from   w  w w.java 2 s.com
    bitmap = bitmap.copy(bitmapConfig, true);
    Canvas canvas = new Canvas(bitmap);
    // new antialised Paint
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // text color - #3D3D3D
    paint.setColor(Color.rgb(61, 61, 61));
    // text size in pixels
    paint.setTextSize((int) (21)); //* scale));
    // text shadow
    paint.setShadowLayer(2f, 1f, 1f, Color.WHITE);
    int x = bitmap.getWidth() - 150;//bounds.width()) - 150;
    int y = bitmap.getHeight() - 27;//bounds.height()) - 30;
    canvas.drawRect(x, y, x + 150, y + 27, paint);
    canvas.drawText(gText, x, y + 20, paint);
    return bitmap;
}

From source file:Main.java

public static final Bitmap complementedBitmapByAlpha(Bitmap bitmap) {
    if (null == bitmap) {
        return null;
    }/* w  ww .j a v a  2  s.c  o  m*/

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width == height) {
        return bitmap;
    }

    int len = width > height ? width : height;
    Bitmap output = Bitmap.createBitmap(len, len, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setAlpha(0);
    canvas.drawPaint(paint);

    if (width > height) {
        int devide = (width - height) / 2;
        canvas.drawBitmap(bitmap, 0, devide, paint_comm);
    } else {
        int devide = (height - width) / 2;
        canvas.drawBitmap(bitmap, devide, 0, paint_comm);
    }
    return output;
}

From source file:Main.java

public static final Bitmap complementedBitmapByColor(Bitmap bitmap, int color) {
    if (null == bitmap) {
        return null;
    }/*from   w  w  w .  j ava2 s . co  m*/

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width == height) {
        return bitmap;
    }

    int len = width > height ? width : height;
    Bitmap output = Bitmap.createBitmap(len, len, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // paint.setAlpha(0);
    paint.setColor(color);
    canvas.drawPaint(paint);

    if (width > height) {
        int devide = (width - height) / 2;
        canvas.drawBitmap(bitmap, 0, devide, paint_comm);
    } else {
        int devide = (height - width) / 2;
        canvas.drawBitmap(bitmap, devide, 0, paint_comm);
    }
    return output;
}