Example usage for android.graphics Paint ANTI_ALIAS_FLAG

List of usage examples for android.graphics Paint ANTI_ALIAS_FLAG

Introduction

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

Prototype

int ANTI_ALIAS_FLAG

To view the source code for android.graphics Paint ANTI_ALIAS_FLAG.

Click Source Link

Document

Paint flag that enables antialiasing when drawing.

Usage

From source file:Main.java

public static int measureTextHeight(int textsize) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textsize);//from   w ww  .  ja v a 2s .  c o  m
    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  v  a 2s.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);//from w w  w.ja va2s.  c om

    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);//from  w  ww  . java  2s  .co  m
    paint.setColor(color);
    return paint;
}

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;
    }//w w w.  j av  a2  s.  co  m
    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;
    }//from   ww  w  .  j  av  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 .  ja v  a  2  s. c  om*/

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

From source file:Main.java

public static Bitmap createFramedImage(Drawable imageDrawable, int borderThickness) {
    int size = Math.min(imageDrawable.getMinimumWidth(), imageDrawable.getMinimumHeight());
    Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    RectF outerRect = new RectF(0, 0, size, size);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);//from w  ww.  ja  va  2 s  .c o m
    canvas.drawRect(outerRect, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    imageDrawable.setBounds(0, 0, size, size);

    // Save the layer to apply the paint
    canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG);
    imageDrawable.draw(canvas);
    canvas.restore();

    // FRAMING THE PHOTO
    float border = size / 15f;

    // 1. Create offscreen bitmap link: http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1035s
    Bitmap framedOutput = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas framedCanvas = new Canvas(framedOutput);
    // End of Step 1

    // Start - TODO IMPORTANT - this section shouldn't be included in the final code
    // It's needed here to differentiate step 2 (red) with the background color of the activity
    // It's should be commented out after the codes includes step 3 onwards
    // Paint squaredPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // squaredPaint.setColor(Color.BLUE);
    // framedCanvas.drawRoundRect(outerRect, 0f, 0f, squaredPaint);
    // End

    // 2. Draw an opaque rounded rectangle link:
    RectF innerRect = new RectF(border, border, size - border, size - border);

    Paint innerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    innerPaint.setColor(Color.RED);
    //      framedCanvas.drawRoundRect(innerRect, cornerRadius, cornerRadius, outerPaint);
    framedCanvas.drawRect(innerRect, innerPaint);

    // 3. Set the Power Duff mode link:
    Paint outerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    outerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));

    // 4. Draw a translucent rounded rectangle link:
    outerPaint.setColor(Color.argb(255, 255, 255, 255));
    //      framedCanvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, outerPaint);
    framedCanvas.drawRect(outerRect, outerPaint);

    // 5. Draw the frame on top of original bitmap
    canvas.drawBitmap(framedOutput, 0f, 0f, null);

    return output;
}

From source file:Main.java

/**
 * create a circle from cutout from a bitmap.
 * does not alter sizes.//from ww w  . ja  v  a 2s.c om
 *
 * @param bitmap the bitmap
 * @see #cutCircleFromBitmap(String, int)
 * @return a bitmap circle cutout
 */
public static Bitmap roundBitMap(Bitmap bitmap) {
    Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);

    BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    paint.setShader(shader);

    Canvas c = new Canvas(circleBitmap);

    c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);

    return circleBitmap;
}