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 Bitmap drawTextToBitmap(Bitmap bitmap, String gText) {
    //Resources resources = gContext.getResources();
    //float scale = resources.getDisplayMetrics().density;

    android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
    // set default bitmap config if none
    if (bitmapConfig == null) {
        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }//from w  w  w.java 2 s. com
    // resource bitmaps are imutable,
    // so we need to convert it to mutable one
    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);
    // draw text to the Canvas center
    //Rect bounds = new Rect();
    //paint.getTextBounds(gText, 0, gText.length(), bounds);
    int x = bitmap.getWidth() - 150;//bounds.width()) - 150;
    int y = bitmap.getHeight() - 27;//bounds.height()) - 30;
    // fill
    canvas.drawRect(x, y, x + 150, y + 27, paint);
    canvas.drawText(gText, x, y + 20, paint);
    return bitmap;
}

From source file:Main.java

/**
 * Frames the input bitmap in a circle.//w w  w .  j a  v  a2s .co  m
 */
public static Bitmap frameBitmapInCircle(Bitmap input) {
    if (input == null) {
        return null;
    }

    // Crop the image if not squared.
    int inputWidth = input.getWidth();
    int inputHeight = input.getHeight();
    int targetX, targetY, targetSize;
    if (inputWidth >= inputHeight) {
        targetX = inputWidth / 2 - inputHeight / 2;
        targetY = 0;
        targetSize = inputHeight;
    } else {
        targetX = 0;
        targetY = inputHeight / 2 - inputWidth / 2;
        targetSize = inputWidth;
    }

    // Create an output bitmap and a canvas to draw on it.
    Bitmap output = Bitmap.createBitmap(targetSize, targetSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // Create a black paint to draw the mask.
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);

    // Draw a circle.
    canvas.drawCircle(targetSize / 2, targetSize / 2, targetSize / 2, paint);

    // Replace the black parts of the mask with the input image.
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(input, targetX /* left */, targetY /* top */, paint);

    return output;
}

From source file:com.irccloud.android.data.model.Avatar.java

public static Bitmap generateBitmap(String text, int textColor, int bgColor, boolean isDarkTheme, int size,
        boolean round) {
    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    if (bitmap != null) {
        Canvas c = new Canvas(bitmap);
        Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
        p.setStyle(Paint.Style.FILL);

        if (isDarkTheme || !round) {
            p.setColor(bgColor);/*from  w ww  . j  a va 2  s. c om*/
            if (round)
                c.drawCircle(size / 2, size / 2, size / 2, p);
            else
                c.drawColor(bgColor);
        } else {
            float[] hsv = new float[3];
            Color.colorToHSV(bgColor, hsv);
            hsv[2] *= 0.8f;
            p.setColor(Color.HSVToColor(hsv));
            c.drawCircle(size / 2, size / 2, (size / 2) - 2, p);
            p.setColor(bgColor);
            c.drawCircle(size / 2, (size / 2) - 2, (size / 2) - 2, p);
        }
        TextPaint tp = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        tp.setTextAlign(Paint.Align.CENTER);
        tp.setTypeface(font);
        tp.setTextSize((int) (size * 0.65));
        tp.setColor(textColor);
        if (isDarkTheme || !round) {
            c.drawText(text, size / 2, (size / 2) - ((tp.descent() + tp.ascent()) / 2), tp);
        } else {
            c.drawText(text, size / 2, (size / 2) - 4 - ((tp.descent() + tp.ascent()) / 2), tp);
        }

        return bitmap;
    } else {
        return null;
    }
}

From source file:Main.java

public static Bitmap cropMaxVisibleBitmap(Drawable drawable, int iconSize) {
    Bitmap tmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);//from   ww  w  .  j a v a  2s . c  o  m
    Canvas canvas = new Canvas(tmp);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    Rect crop = new Rect(tmp.getWidth(), tmp.getHeight(), -1, -1);
    for (int y = 0; y < tmp.getHeight(); y++) {
        for (int x = 0; x < tmp.getWidth(); x++) {
            int alpha = (tmp.getPixel(x, y) >> 24) & 255;
            if (alpha > 0) { // pixel is not 100% transparent
                if (x < crop.left)
                    crop.left = x;
                if (x > crop.right)
                    crop.right = x;
                if (y < crop.top)
                    crop.top = y;
                if (y > crop.bottom)
                    crop.bottom = y;
            }
        }
    }

    if (crop.width() <= 0 || crop.height() <= 0) {
        return Bitmap.createScaledBitmap(tmp, iconSize, iconSize, true);
    }

    // We want to crop a square region.
    float size = Math.max(crop.width(), crop.height());
    float xShift = (size - crop.width()) * 0.5f;
    crop.left -= Math.floor(xShift);
    crop.right += Math.ceil(xShift);

    float yShift = (size - crop.height()) * 0.5f;
    crop.top -= Math.floor(yShift);
    crop.bottom += Math.ceil(yShift);

    Bitmap finalImage = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
    canvas.setBitmap(finalImage);
    float scale = iconSize / size;

    canvas.scale(scale, scale);
    canvas.drawBitmap(tmp, -crop.left, -crop.top, new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
    canvas.setBitmap(null);
    return finalImage;
}

From source file:com.freshdigitable.udonroad.TimelineDecoration.java

TimelineDecoration(Context context) {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    final int dividerColor = ContextCompat.getColor(context, R.color.divider);
    paint.setColor(dividerColor);//from   w w  w  .  ja va2  s  .  c  om
    this.dividerHeight = 1;
}

From source file:com.luseen.spacenavigation.BezierView.java

public BezierView(Context context, int backgroundColor) {
    super(context);
    this.context = context;
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    path = new Path();
    paint.setColor(backgroundColor);//from w  w  w.  j a v  a2s. c o m
    paint.setStrokeWidth(0);
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
}

From source file:com.gosuncn.core.ui.widget.BezierView.java

public BezierView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    path = new Path();
    paint.setColor(((ColorDrawable) getBackground()).getColor());
    paint.setStrokeWidth(0);//from   w  w  w  . j  av  a  2  s. co m
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
}

From source file:org.mariotaku.twidere.text.OriginalStatusSpan.java

public OriginalStatusSpan(Context context) {
    mBounds = new RectF();
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDarkLightColors = new int[2];
    final float density = context.getResources().getDisplayMetrics().density;
    mCornerRadius = density * 2;//www  . j  a v a  2  s  .c o m
    mPaint.setStrokeWidth(density);
    mPadding = (int) (density * 4);
    ThemeUtils.getDarkLightForegroundColors(context, mDarkLightColors);
}

From source file:com.nextgis.maplibui.util.NotificationHelper.java

public static Bitmap getLargeIcon(int iconResourceId, Resources resources) {
    Bitmap icon = BitmapFactory.decodeResource(resources, iconResourceId);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return icon;

    int iconSize = ControlHelper.dpToPx(40, resources);
    int innerIconSize = ControlHelper.dpToPx(24, resources);
    icon = Bitmap.createScaledBitmap(icon, iconSize, iconSize, false);
    Bitmap largeIcon = icon.copy(Bitmap.Config.ARGB_8888, true);
    icon = Bitmap.createScaledBitmap(icon, innerIconSize, innerIconSize, false);

    Canvas canvas = new Canvas(largeIcon);
    int center = canvas.getHeight() / 2;
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(resources.getColor(R.color.accent));
    canvas.drawCircle(center, center, center, paint);
    paint.setColor(Color.WHITE);//from  ww  w .j  a  v  a2s .  c  o m
    canvas.drawBitmap(icon, center - icon.getWidth() / 2, center - icon.getWidth() / 2, paint);

    return largeIcon;
}

From source file:com.efunds.moa.component.customview.process.AnnularView.java

private void init(Context context) {
    mWhitePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mWhitePaint.setStyle(Paint.Style.STROKE);
    mWhitePaint.setStrokeWidth(Helper.dpToPixel(3, getContext()));
    mWhitePaint.setColor(Color.WHITE);

    mGreyPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mGreyPaint.setStyle(Paint.Style.STROKE);
    mGreyPaint.setStrokeWidth(Helper.dpToPixel(3, getContext()));
    mGreyPaint.setColor(ContextCompat.getColor(context, R.color.progress_default_color));

    mBound = new RectF();
}