下面列出了android.graphics.Paint#ANTI_ALIAS_FLAG 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Bitmap roundCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int width = source.getWidth();
int height = source.getHeight();
rectF.set(0, 0, width, height);
Bitmap squared = Bitmap.createBitmap(source, 0, 0, width, height);
Bitmap result = pool.get(width, height, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint
.ANTI_ALIAS_FLAG);
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader
.TileMode.CLAMP));
canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint);
return result;
}
private void init(Context c){
Log.d(TAG, "init called");
// Create the colour array
mColours = new int[6];
mColours[4] = Color.parseColor("#1bc5a4");
mColours[1] = Color.parseColor("#9b59b6");
mColours[0] = Color.parseColor("#2ecc71");
mColours[2] = Color.parseColor("#e74c3c");
mColours[3] = Color.parseColor("#3498db");
mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBarPaint.setStyle(Paint.Style.FILL);
mBarNumberPaint = new Paint();
mBarNumberPaint.setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));
mBarNumberPaint.setColor(c.getResources().getColor(R.color.text_main));
mBarNumberPaint.setTextSize(100);
mBarNumberPaint.setTextAlign(Align.CENTER);
mNameLabelPaint = new Paint();
mNameLabelPaint.setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));
mNameLabelPaint.setColor(c.getResources().getColor(R.color.text_main));
mNameLabelPaint.setTextAlign(Align.CENTER);
mNameLabelPaint.setTextSize(140);
}
private void initObjects() {
mPath = new Path();
mSlideHandler = new SlideHandler();
mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mStrokePaint.setStyle(Style.STROKE);
mStrokePaint.setColor(mStrokeColor);
mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mMaskPaint.setStyle(Style.FILL);
mMaskPaint.setColor(mMaskColor);
mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mButtonPaint.setStyle(Style.FILL);
mButtonPaint.setColor(mButtonColor);
}
private void initPaint() {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
res = getResources();
source = BitmapFactory.decodeResource(res, R.drawable.cat);
cover = BitmapFactory.decodeResource(res, R.drawable.circle);
mStartColor = res.getColor(R.color.cpb_red);
mEndColor = res.getColor(R.color.cpb_green);
mPaint.setColor(Color.parseColor("#536DFE"));
mbackPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mbackPaint.setStyle(Paint.Style.STROKE);
mbackPaint.setStrokeWidth(3);
mbackPaint.setColor(Color.WHITE);
}
private Bitmap createBgBitmap(int w, int h, String text, int textColor) {
Bitmap bgPicBitmap = getBitmap();
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bgPicBitmap, 0, 0, null);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.GRAY);
canvas.drawRect(rect,paint);
paint.setColor(textColor);
float textSize = 150;
paint.setTextSize(textSize);
int cx = w / 2;
int cy = h / 2;
float measureText = paint.measureText(text);
//将文字画在中间
canvas.drawText(text, cx - measureText / 2, cy + textSize / 2, paint);
canvas = null;
paint = null;
return bitmap;
}
@Override
public void drawIcon(Canvas canvas, float fraction, Drawable drawable, int colorOfIcon,
WidthAndHeightOfView widthAndHeightOfView) {
int centerX = widthAndHeightOfView.getWidth() / 2;
int centerY = widthAndHeightOfView.getHeight() / 2 - 150;
canvas.save();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
float newFraction = (fraction - 0.65f) / 0.35f;
paint.setColor(Color.parseColor("#e53935"));
canvas.drawCircle(centerX, centerY - 50, 100 * (1 - newFraction), paint);
paint.setColor(Color.parseColor("#fdd835"));
canvas.drawCircle(centerX -35, centerY + 35,100 * (1 - newFraction), paint);
paint.setColor(Color.parseColor("#1e88e5"));
canvas.drawCircle(centerX + 35, centerY + 35, 100 * (1 - newFraction), paint);
canvas.restore();
canvas.save();
Path path = new Path();
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
canvas.concat(matrix);
path.addCircle(centerX, centerY, bitmap.getHeight() * 1.5f * newFraction, Path.Direction.CW);
canvas.clipPath(path);
canvas.drawBitmap(bitmap, centerX - bitmap.getWidth() / 2, centerY - bitmap.getHeight() / 2, paint);
canvas.restore();
}
/**
* Initialize this view.
*
* @param context
*/
private void init(Context context) {
this.context = context;
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(Color.BLACK);
textPaint.setTextSize(60);
dropTargetView = new ImageView(context);
dropTargetView.setImageResource(R.drawable.placeholder);
dropTargetView.setScaleType(ImageView.ScaleType.FIT_XY);
dropTargetView.setVisibility(View.GONE);
addView(dropTargetView);
swapTargetView = new ImageView(context);
swapTargetView.setImageResource(R.drawable.swap_candidate);
swapTargetView.setScaleType(ImageView.ScaleType.FIT_XY);
swapTargetView.setVisibility(View.GONE);
addView(swapTargetView);
LayoutInflater inflater = LayoutInflater.from(context);
// Drop area
editDropAreaView = inflater.inflate(R.layout.drop_area, this, false);
addView(editDropAreaView);
if (editDropAreaText != null) { // Use custom text for drop area
TextView dropAreaTextView = (TextView) editDropAreaView.findViewById(R.id.drop_area__label);
dropAreaTextView.setText(editDropAreaText);
}
}
private void init() {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStrokeWidth(4);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStyle(Paint.Style.STROKE);
mPath = new LinkedHashMap<>();
}
public ShapeBackgroundSpan(int color, Shape shape, boolean stroke){
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(color);
this.shape = shape;
if(stroke){
paint.setStyle(Paint.Style.STROKE);
}else{
paint.setStyle(Paint.Style.FILL);
}
}
private void init() {
//
// set up paint components
//
float scale = getContext().getResources().getDisplayMetrics().density;
// formula from framework: px = (int) (dps * scale + 0.5f)
ringWidth = (int) (7 * scale + 0.5f);
endPercentProgress = 0;
int startSweep = 0;
endSweep = 0;
currentSweep = startSweep;
int progressColor = ContextCompat.getColor(getContext(), R.color.record_highlight);
progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
progressPaint.setStyle(Paint.Style.STROKE);
progressPaint.setColor(progressColor);
progressPaint.setStrokeWidth(ringWidth);
progressPaint.setStrokeCap(Paint.Cap.ROUND);
circle = new RectF(0, 0, getWidth(), getHeight());
progressPath = new Path();
}
@Override
protected void init() {
super.init();
// piechart has no offsets
mOffsetTop = 0;
mOffsetBottom = 0;
mOffsetLeft = 0;
mOffsetRight = 0;
mShift = Utils.convertDpToPixel(mShift);
mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHolePaint.setColor(Color.WHITE);
mCenterTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterTextPaint.setColor(mColorDarkBlue);
mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));
mCenterTextPaint.setTextAlign(Align.CENTER);
mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
mValuePaint.setColor(Color.WHITE);
mValuePaint.setTextAlign(Align.CENTER);
mListener = new PieChartTouchListener(this);
// for the piechart, drawing values is enabled
mDrawYValues = true;
}
private void init(Context context) {
singleWaveWidth = context.getResources().getDimensionPixelSize(R.dimen.wave_width);
singleWaveWidth_fix = singleWaveWidth;
singleWaveHeightDeltaY = context.getResources().getDimensionPixelSize(R.dimen.wave_height);
singleWaveHeightDeltaY_fix = singleWaveHeightDeltaY;
color = context.getResources().getColor(R.color.wave_color);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(color);
}
public ILetter(int x, int y) {
super(x, y);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Config.WHITE);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setStrokeWidth(20);
mCurY += LENGTH / 2;
}
public CaptionMapObject(Object id, Drawable drawable, Point position,
Point pivotPoint, boolean isTouchable, boolean isScalable) {
super(id, drawable, position, pivotPoint, isTouchable, isScalable);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(14);
paint.setTypeface(Typeface.SANS_SERIF);
paint.setFakeBoldText(true);
paint.setShadowLayer(1, 0, 0, Color.BLACK);
}
public DynamicPageIndicator2(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final int density = (int) context.getResources().getDisplayMetrics().density;
// Load attributes
final TypedArray a = getContext().obtainStyledAttributes(
attrs, R.styleable.DynamicPageIndicator2, defStyle, 0);
dotDiameter = a.getDimensionPixelSize(R.styleable.DynamicPageIndicator2_ads_dotDiameter,
DEFAULT_DOT_SIZE * density);
dotRadius = dotDiameter / 2;
halfDotRadius = dotRadius / 2;
gap = a.getDimensionPixelSize(R.styleable.DynamicPageIndicator2_ads_dotGap,
DEFAULT_GAP * density);
animDuration = (long) a.getInteger(R.styleable.DynamicPageIndicator2_ads_animationDuration,
DEFAULT_ANIM_DURATION);
animHalfDuration = animDuration / 2;
unselectedColour = a.getColor( R.styleable.DynamicPageIndicator2_ads_pageIndicatorColor,
DEFAULT_UNSELECTED_COLOUR);
selectedColour = a.getColor( R.styleable.DynamicPageIndicator2_ads_currentPageIndicatorColor,
DEFAULT_SELECTED_COLOUR);
a.recycle();
unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
unselectedPaint.setColor(unselectedColour);
selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
selectedPaint.setColor(selectedColour);
interpolator = new FastOutSlowInInterpolator();
// create paths & rect now – reuse & rewind later
combinedUnselectedPath = new Path();
unselectedDotPath = new Path();
unselectedDotLeftPath = new Path();
unselectedDotRightPath = new Path();
rectF = new RectF();
addOnAttachStateChangeListener(this);
}
private void init() {
mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
roundPath = new Path();
borderPath = new Path();
borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
borderPaint.setStrokeWidth(borderWidth);
setScaleType(ScaleType.CENTER_CROP);
}
static
Paint configurePaint(Resources resources, int dimenResource, int colorResource)
{
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(resources.getDimension(dimenResource));
paint.setColor(resources.getColor(colorResource));
paint.setHinting(Paint.HINTING_ON);
return paint;
}
private ContentValues newContentValues(Bitmap icon, String label, int lowResBackgroundColor) {
ContentValues values = new ContentValues();
values.put(IconDB.COLUMN_ICON, Utilities.flattenBitmap(icon));
values.put(IconDB.COLUMN_LABEL, label);
values.put(IconDB.COLUMN_SYSTEM_STATE, mSystemState);
if (lowResBackgroundColor == Color.TRANSPARENT) {
values.put(IconDB.COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(
Bitmap.createScaledBitmap(icon,
icon.getWidth() / LOW_RES_SCALE_FACTOR,
icon.getHeight() / LOW_RES_SCALE_FACTOR, true)));
} else {
synchronized (this) {
if (mLowResBitmap == null) {
mLowResBitmap = Bitmap.createBitmap(icon.getWidth() / LOW_RES_SCALE_FACTOR,
icon.getHeight() / LOW_RES_SCALE_FACTOR, Bitmap.Config.RGB_565);
mLowResCanvas = new Canvas(mLowResBitmap);
mLowResPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
}
mLowResCanvas.drawColor(lowResBackgroundColor);
mLowResCanvas.drawBitmap(icon, new Rect(0, 0, icon.getWidth(), icon.getHeight()),
new Rect(0, 0, mLowResBitmap.getWidth(), mLowResBitmap.getHeight()),
mLowResPaint);
values.put(IconDB.COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(mLowResBitmap));
}
}
return values;
}
public void setVectorArrays(String[] vectors) {
if (vectors == null) {
return;
}
mPathPaints = new Paint[vectors.length];
mPaths = new Path[vectors.length];
for (int i = 0; i < vectors.length; i++) {
mPaths[i] = VectorPathParser.createPathFromPathData(vectors[i]);
mPathPaints[i] = new Paint(Paint.ANTI_ALIAS_FLAG);
}
requestLayout();
invalidate();
}
/**
* 自定义分割线
*
* @param context
* @param orientation 列表方向
* @param dividerHeight 分割线高度
* @param dividerColor 分割线颜色
*/
public RecycleViewDivider(Context context, int orientation, int dividerHeight, int dividerColor) {
this(context, orientation);
mDividerHeight = dividerHeight;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(dividerColor);
mPaint.setStyle(Paint.Style.FILL);
}