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

/** Return a bitmap identical to src with rounded corners. */
public static final Bitmap roundCornersRGB888(Bitmap src, int roundPixles) {
    final Bitmap output = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // TODO: document what is special about this color
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);/*from w ww  .  jav  a  2  s .c o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPixles, roundPixles, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(src, 0, 0, paint);

    return output;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    if (bitmap == null) {
        return null;
    }/*from  ww w .j ava  2s. c o  m*/
    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);
    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 getRoundedCornerBitmap(Bitmap bitmap, float radius) {
    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);//  w  w w. j  av a  2  s .c  om
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, radius, radius, 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) {

    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);//from w  ww.j  av  a  2s.  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 circleBitmap(Bitmap source, boolean recycle) {
    if (source == null) {
        return null;
    }// www  .  j a v a2 s.  c o  m

    // Create custom bitmap
    Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // Compute sizes
    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, source.getWidth(), source.getHeight());
    final RectF rectF = new RectF(rect);

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

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

    if (recycle) {
        source.recycle();
    }

    return output;
}

From source file:Main.java

public static Bitmap buildSequence(Context context, String text) {
    Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
    Canvas myCanvas = new Canvas(myBitmap);
    Paint paint = new Paint();
    //Typeface font = Typeface.createFromAsset(context.getAssets(),"fonts/7LED.ttf");
    paint.setAntiAlias(true);//from  ww w.ja v  a 2  s .  c  o m
    paint.setSubpixelText(true);
    //paint.setTypeface(font);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.YELLOW);
    paint.setTextSize(65);
    paint.setTextAlign(Paint.Align.CENTER);
    myCanvas.drawText(text, 80, 60, paint);
    return myBitmap;
}

From source file:org.opensilk.common.ui.util.ThemeUtils.java

public static Drawable colorizeBitmapDrawableCopy(Context context, int resId, int newColor) {
    final Drawable maskDrawable = context.getResources().getDrawable(resId);
    if (!(maskDrawable instanceof BitmapDrawable)) {
        return null;
    }/*w  ww . j a v  a 2  s . c  o  m*/

    final Bitmap maskBitmap = ((BitmapDrawable) maskDrawable).getBitmap();
    final int width = maskBitmap.getWidth();
    final int height = maskBitmap.getHeight();

    final Bitmap outBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(outBitmap);
    canvas.drawBitmap(maskBitmap, 0, 0, null);

    final Paint maskedPaint = new Paint();
    maskedPaint.setColor(newColor);
    maskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    canvas.drawRect(0, 0, width, height, maskedPaint);

    return new BitmapDrawable(context.getResources(), outBitmap);
}

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);

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

    paint.setAntiAlias(true);//from  w  w w  .  j a  va2 s  . 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);
    bitmap.recycle();
    return output;
}

From source file:Main.java

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);

    paint.setAntiAlias(true);//from www  . j a va2s .co  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, 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 getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {

    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);//from   w  w w  . ja  v  a2 s  .c om

    canvas.drawARGB(0, 0, 0, 0);

    paint.setColor(color);

    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;

}