Example usage for android.graphics Color WHITE

List of usage examples for android.graphics Color WHITE

Introduction

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

Prototype

int WHITE

To view the source code for android.graphics Color WHITE.

Click Source Link

Usage

From source file:Main.java

public static Bitmap getTextImage(String text, float size, int width, int height) {
    final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Paint paint = new Paint();
    final Canvas canvas = new Canvas(bmp);

    canvas.drawColor(Color.WHITE);

    paint.setColor(Color.BLACK);/*from ww w.  ja v a2  s.com*/
    paint.setStyle(Style.FILL);
    paint.setAntiAlias(true);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(size);
    paint.setTypeface(Typeface.DEFAULT);
    canvas.drawText(text, width / 2, height / 2, paint);

    return bmp;
}

From source file:Main.java

public static Bitmap getBitmap(Bitmap background, Bitmap contour, float alpha) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);//from ww  w. ja  v a  2 s  . com
    paint.setColor(Color.WHITE);
    paint.setDither(false);
    Bitmap bitmap = Bitmap.createBitmap(contour.getWidth(), contour.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Matrix m = new Matrix();
    m.setScale(contour.getWidth() * 1.0f / background.getWidth(),
            contour.getHeight() * 1.0f / background.getHeight());
    paint.setAlpha((int) (alpha * 0xff));
    canvas.drawBitmap(background, m, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    paint.setAlpha(0xff);
    canvas.drawBitmap(contour, 0, 0, paint);
    return bitmap;
}

From source file:Main.java

public static Bitmap addLabelToBitmap(Bitmap src, String label) {
    float densityFactor = Resources.getSystem().getDisplayMetrics().density;
    final float textPadding = src.getWidth() * 0.05f;

    Bitmap result = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Paint textPaint = new Paint();
    textPaint.setAntiAlias(true);//w w  w. j av  a2 s .c  o  m
    textPaint.setTextSize(12 * densityFactor);
    textPaint.setColor(Color.WHITE);
    textPaint.setStrokeWidth(2 * densityFactor);
    textPaint.setShadowLayer(1 * densityFactor, 0, 0, Color.BLACK);

    float textWidth = textPaint.measureText(label);

    float scaleFactor = (src.getWidth() - textPadding * 2) / textWidth;

    canvas.drawBitmap(src, 0, 0, textPaint);

    canvas.save();
    canvas.scale(scaleFactor, scaleFactor);
    float textPosX = (src.getWidth() / scaleFactor - textWidth) / 2;
    float textPosY = (src.getHeight() - textPadding) / scaleFactor;

    canvas.drawText(label, textPosX, textPosY, textPaint);
    canvas.restore();
    return result;
}

From source file:Main.java

public static int colorForString(String color) {
    if (color == null) {
        return (Color.BLACK);
    }/*from  ww  w. j  av a  2s . c  o m*/
    String c = color.toLowerCase();
    if (c.equals("red")) {
        return (Color.argb(150, 255, 0, 0));
    } else if (c.equals("yellow")) {
        //         return(Color.YELLOW);
        return (Color.argb(200, 255, 180, 0));
    } else if (c.equals("green")) {
        return (Color.GREEN);
    } else if (c.equals("blue")) {
        return (Color.BLUE);
    } else if (c.equals("purple")) {
        return (Color.argb(255, 255, 0, 255));
    } else if (c.equals("clear")) {
        return (Color.WHITE);
    } else {
        return (Color.BLACK);
    }
}

From source file:Main.java

public static Bitmap roundCorners(final Bitmap bitmap, final int radiusX, final int radiusY) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Paint paint = new Paint();
    paint.setAntiAlias(true);//from   w  w  w.  ja  v a  2 s . c om
    paint.setColor(Color.WHITE);

    Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(clipped);
    canvas.drawRoundRect(new RectF(0, 0, width, height), radiusX, radiusY, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

    Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    canvas = new Canvas(rounded);
    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.drawBitmap(clipped, 0, 0, paint);

    return rounded;
}

From source file:Main.java

public static Bitmap getBitmapFromView(View view) {
    //Define a bitmap with the same size as the view
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    //Bind a canvas to it
    Canvas canvas = new Canvas(returnedBitmap);
    //Get the view's background
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null)
        //has background drawable, then draw it on the canvas
        bgDrawable.draw(canvas);//from w w w.jav  a  2  s.c  o  m
    else
        //does not have background drawable, then draw white background on the canvas
        canvas.drawColor(Color.WHITE);
    // draw the view on the canvas
    view.draw(canvas);
    //return the bitmap
    return returnedBitmap;
}

From source file:Main.java

/**
 * @param color/*from   www.j  a  v  a2  s .  c om*/
 * @return
 */
public static int getTextColor(int color) {
    if (luminosity(color) > 122)
        return Color.BLACK;
    else
        return Color.WHITE;

}

From source file:Main.java

public static int getBlackWhiteColor(int color) {
    double darkness = 1
            - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
    if (darkness >= 0.5) {
        return Color.WHITE;
    } else/*from w ww. j a v a 2s. c o m*/
        return Color.BLACK;
}

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;
    }/* ww  w  . j a  v a  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 void drawCropRect(Canvas canvas, RectF bounds) {
    Paint p = new Paint();
    p.setStyle(Paint.Style.STROKE);
    p.setColor(Color.WHITE);
    p.setStrokeWidth(3);//w  w  w .j  a v a  2  s.co  m
    canvas.drawRect(bounds, p);
}