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

Source Link

Document

Create a new paint with default settings.

Usage

From source file:Main.java

public static Bitmap toCircleBitmap(Bitmap bitmap) {

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int r = width < height ? width : height;

    Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(buffer);
    Paint paint = new Paint();
    paint.setAntiAlias(true);//from  w w w  .  j a  v  a2  s .c  o m
    RectF rect = new RectF(0, 0, r, r);

    canvas.drawCircle(r / 2, r / 2, r / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, null, rect, paint);
    bitmap.recycle();
    return buffer;
}

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);// w ww .j  a 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:Main.java

public static Bitmap roundCorners(Bitmap bitmap, float radius) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);// ww w.j  a  va2 s . c om

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    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 highlightSelectedFaceThumbnail(Bitmap originalBitmap) {
    Bitmap bitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);/*from  w  w w.ja  va  2  s .  c  o m*/
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.parseColor("#3399FF"));
    int stokeWidth = Math.max(originalBitmap.getWidth(), originalBitmap.getHeight()) / 10;
    if (stokeWidth == 0) {
        stokeWidth = 1;
    }
    bitmap.getWidth();
    paint.setStrokeWidth(stokeWidth);
    canvas.drawRect(0, 0, bitmap.getWidth(), bitmap.getHeight(), paint);

    return bitmap;
}

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 = 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);//from w  ww  .j  a  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 joinBitmaps(Bitmap first, Bitmap second) {
    Bitmap result = Bitmap.createBitmap(first.getWidth(), first.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Paint bitmapPaint = new Paint();
    if (second.getWidth() != first.getWidth() && second.getHeight() != first.getHeight()) {
        second = createScaledToFillBitmap(second, first.getWidth(), first.getHeight());
    }/* w w w.j  av  a2s  .  c om*/

    canvas.drawBitmap(first, 0, 0, bitmapPaint);
    canvas.drawBitmap(second, 0, 0, bitmapPaint);

    return result;
}

From source file:Main.java

public static Bitmap formatUserAvatar(Bitmap photo) {
    int maskColor = 0xff424242;
    Paint cornerPaint = new Paint();
    cornerPaint.setAntiAlias(true);/*from   w w w . j a  v a2  s. c o m*/
    cornerPaint.setColor(maskColor);
    Rect roundedCornerRect = new Rect(0, 0, 256, 256);
    RectF roundedCornerRectF = new RectF(roundedCornerRect);
    Bitmap roundedCornerBitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_8888);
    Canvas roundedCornerCanvas = new Canvas(roundedCornerBitmap);
    roundedCornerCanvas.drawARGB(0, 0, 0, 0);
    roundedCornerCanvas.drawRoundRect(roundedCornerRectF, 128, 128, cornerPaint);
    cornerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(photo, 256, 256, true);
    roundedCornerCanvas.drawBitmap(scaledBitmap, roundedCornerRect, roundedCornerRect, cornerPaint);
    return roundedCornerBitmap;
}

From source file:Main.java

public static Bitmap getPlusBitmap(Context context, String s) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);//from   w  ww . j a  v a 2 s  .  c o  m
    Bitmap bitmap = BitmapFactory.decodeStream(getCommunityPicInputStream(s));
    Bitmap bitmap1;
    if (bitmap != null) {
        Bitmap bitmap2 = BitmapFactory.decodeResource(context.getResources(), 0x7f02003f);
        bitmap1 = Bitmap.createBitmap(bitmap.getWidth() + bitmap2.getWidth() / 2,
                bitmap.getHeight() + bitmap2.getHeight() / 2, android.graphics.Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap1);
        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawBitmap(bitmap, 0.0F, 0.0F, paint);
        bitmap.recycle();
        canvas.drawBitmap(bitmap2, bitmap.getWidth() - bitmap2.getWidth() / 2,
                bitmap.getHeight() - bitmap2.getHeight() / 2, paint);
        bitmap2.recycle();
    } else {
        bitmap1 = null;
    }
    return bitmap1;
}

From source file:Main.java

public static Bitmap getNewCombinedByPiecesAlsoGrayscaled(List<Bitmap> bitmapList, int currentStage,
        int numStages) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);//from   w  w  w. j  a  v a 2  s. c  o m
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(colorMatrixColorFilter);

    //i mean, don't use greyscale, but add here all the functionalities to reuse the canvas
    int originalTotalWidth = bitmapList.get(0).getWidth() * numStages;
    Bitmap finalBitmap = Bitmap.createBitmap(originalTotalWidth, bitmapList.get(0).getHeight(),
            Bitmap.Config.ARGB_8888);
    float delta = 0f;
    Canvas comboImage = new Canvas(finalBitmap);
    for (int i = 0; i < numStages; i++) {
        comboImage.translate(delta, 0f);
        if (i > currentStage) {
            comboImage.drawBitmap(bitmapList.get(i), 0f, 0f, paint);
        } else {
            comboImage.drawBitmap(bitmapList.get(i), 0f, 0f, null);
        }
        delta = originalTotalWidth / numStages;
    }
    return finalBitmap;
}

From source file:Main.java

public static Bitmap toGreyBitmap(Bitmap bitmap) {
    Bitmap grey = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(grey);
    Paint p = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);//from w ww. j  a  v a 2s.c om
    p.setColorFilter(new ColorMatrixColorFilter(cm));
    c.drawBitmap(bitmap, 0, 0, p);
    return grey;
}