Example usage for android.graphics Paint setColor

List of usage examples for android.graphics Paint setColor

Introduction

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

Prototype

public void setColor(@ColorInt int color) 

Source Link

Document

Set the paint's color.

Usage

From source file:Main.java

public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xffffffff;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);/*from  w w w.j  ava  2s  .c o m*/
    canvas.drawARGB(0, 255, 255, 255);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    bitmap.recycle();
    return output;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 50;

    paint.setAntiAlias(true);/*ww w.jav  a2s .c o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    try {//from   w w  w.  j  ava 2  s .  c  o m
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        return output;
    } catch (Exception e) {
        e.printStackTrace();
        return bitmap;
    }
}

From source file:Main.java

/**
 * Gets the bitmap with rounded corners//from   w w  w.  j a v a  2 s  . c  om
 *
 * @param bitmap Bitmap for processing
 * @param pixels Picture diameter in pixels
 * @return Rounded picture
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap fillet(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);/*from   ww w . j  a va  2s. c  o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.BLACK);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int radiusPixel) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = radiusPixel;

    paint.setAntiAlias(true);/*from  w w w .j  a  v  a2  s  .com*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 12;

    paint.setAntiAlias(true);//  w  w w. java2s  .c o m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    if (null != bitmap) {
        bitmap.recycle();
        bitmap = null;
    }

    return output;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = bitmap.getWidth() / 2;

    paint.setAntiAlias(true);//from  w w  w  .ja  va  2  s . c  om
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 12;

    paint.setAntiAlias(true);//from   ww  w  .  j  a va2  s  . co  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap createRoundCornerBitmap(Bitmap bitmap, float roundPx, boolean lt, boolean rt, boolean lb,
        boolean rb) {
    Bitmap roundCornerBitmap = createRoundCornerBitmap(bitmap, roundPx);
    Canvas canvas = new Canvas(roundCornerBitmap);
    canvas.drawARGB(0, 0, 0, 0);/*w ww.  j av a 2 s. c o  m*/
    int bw = bitmap.getWidth();
    int bh = bitmap.getHeight();
    int centerW = bw / 2;
    int centerH = bh / 2;

    Paint paint = new Paint();
    Paint defaultPaint = new Paint();
    int color = 0xff424242;
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    paint.setAntiAlias(true);
    paint.setColor(color);

    Bitmap cutBitmap = null;
    Canvas cutCanvas = null;
    if (!lt) {
        cutBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888);
        cutCanvas = new Canvas(cutBitmap);
        cutCanvas.drawRect(0, 0, centerW, centerH, defaultPaint);
        cutCanvas.drawBitmap(bitmap, 0, 0, paint);
        canvas.drawBitmap(cutBitmap, 0, 0, defaultPaint);
        cutBitmap.recycle();
    }
    if (!rt) {
        cutBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888);
        cutCanvas = new Canvas(cutBitmap);
        cutCanvas.drawRect(centerW, 0, bw, centerH, defaultPaint);
        cutCanvas.drawBitmap(bitmap, 0, 0, paint);
        canvas.drawBitmap(cutBitmap, 0, 0, defaultPaint);
        cutBitmap.recycle();
    }
    if (!lb) {
        cutBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888);
        cutCanvas = new Canvas(cutBitmap);
        cutCanvas.drawRect(0, centerH, centerW, bh, defaultPaint);
        cutCanvas.drawBitmap(bitmap, 0, 0, paint);
        canvas.drawBitmap(cutBitmap, 0, 0, defaultPaint);
        cutBitmap.recycle();
    }
    if (!rb) {
        cutBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888);
        cutCanvas = new Canvas(cutBitmap);
        cutCanvas.drawRect(centerW, centerH, bw, bh, defaultPaint);
        cutCanvas.drawBitmap(bitmap, 0, 0, paint);
        canvas.drawBitmap(cutBitmap, 0, 0, defaultPaint);
        cutBitmap.recycle();
    }
    return roundCornerBitmap;
}