Java Code Examples for android.graphics.Paint.setAntiAlias()

The following are Jave code examples for showing how to use setAntiAlias() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: XERUNG   File: RippleView.java   View Source Code Vote up 6 votes
public Bitmap makeCircleFromBitmap(Bitmap output) {
	Canvas canvas = new Canvas(output);
	canvas.drawARGB(0, 0, 0, 0);
	Paint paint = new Paint();
	paint.setAntiAlias(true);
	if (rippleColor == null) {
		paint.setColor(makePressColor(255));
	}else {
		paint.setColor(rippleColor);
	}
	canvas.drawCircle(x, y, radius, paint);
	if (radius > getHeight() / rippleSize)
		radius += rippleSpeed;
	if (radius >= getWidth()) {
		x = -1;
		y = -1;
		radius = getHeight() / rippleSize;
		if(isEnabled() && clickAfterRipple == true && onClickListener != null)
			onClickListener.onClick(this);
	}
	return output;
}
 
Example 2
Project: ForeverLibrary   File: GlideCircleTransform.java   View Source Code Vote up 6 votes
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;

    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
Example 3
Project: HeadlineNews   File: ImageUtils.java   View Source Code Vote up 6 votes
/**
 * 转为圆角图片
 *
 * @param src     源图片
 * @param radius  圆角的度数
 * @param recycle 是否回收
 * @return 圆角图片
 */
public static Bitmap toRoundCorner(final Bitmap src, final float radius, final boolean recycle) {
    if (null == src) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    Paint paint = new Paint();
    Canvas canvas = new Canvas(ret);
    Rect rect = new Rect(0, 0, width, height);
    paint.setAntiAlias(true);
    canvas.drawRoundRect(new RectF(rect), radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, rect, rect, paint);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 4
Project: ForeverLibrary   File: MyImageView.java   View Source Code Vote up 6 votes
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int width = getWidth();
    int height = getHeight();

    Paint paint = new Paint();
    paint.setColor(Color.rgb(255, 255, 255));
    paint.setAntiAlias(true);
    paint.setStrokeWidth(t(5));

    canvas.drawLine(0, 0, 0, t(18), paint);
    canvas.drawLine(0, 0, t(18), 0, paint);

    canvas.drawLine(0, height - t(18), 0, height, paint);
    canvas.drawLine(0, height, t(18), height, paint);

    canvas.drawLine(width - t(18), 0, width, 0, paint);
    canvas.drawLine(width, 0, width, t(18), paint);

    canvas.drawLine(width, height - t(18), width, height, paint);
    canvas.drawLine(width - t(18), height, width, height, paint);
}
 
Example 5
Project: Amazing   File: FadingPic.java   View Source Code Vote up 6 votes
private void init(Context context, AttributeSet attrs) {
    bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.beautify);
    width = bitmap.getWidth();
    height = bitmap.getHeight();
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    paint.setShader(new LinearGradient(0, 0, 0, height, 0x00000000, 0xff000000, Shader.TileMode.CLAMP));

    Matrix matrix = new Matrix();
    matrix.setScale(1, -1);
    //matrix.setRotate(180); 不能形成镜像效果
    rotateBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

    paint1 = new Paint();
    paint1.setAntiAlias(true);
    paint1.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    paint1.setShader(new LinearGradient(0, height, 0, 2 * height, 0xff000000, 0x00000000, Shader.TileMode.CLAMP));
}
 
Example 6
Project: Tribe   File: EaseImageView.java   View Source Code Vote up 5 votes
private void init(Context context, AttributeSet attrs) {
    //init the value
    borderWidth = 0;
    borderColor = 0xddffffff;
    pressAlpha = 0x42;
    pressColor = 0x42000000;
    radius = 16;
    shapeType = 0;

    // get attribute of EaseImageView
    if (attrs != null) {
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.EaseImageView);
        borderColor = array.getColor(R.styleable.EaseImageView_ease_border_color, borderColor);
        borderWidth = array.getDimensionPixelOffset(R.styleable.EaseImageView_ease_border_width, borderWidth);
        pressAlpha = array.getInteger(R.styleable.EaseImageView_ease_press_alpha, pressAlpha);
        pressColor = array.getColor(R.styleable.EaseImageView_ease_press_color, pressColor);
        radius = array.getDimensionPixelOffset(R.styleable.EaseImageView_ease_radius, radius);
        shapeType = array.getInteger(R.styleable.EaseImageView_ease_shape_type, shapeType);
        array.recycle();
    }

    // set paint when pressed
    pressPaint = new Paint();
    pressPaint.setAntiAlias(true);
    pressPaint.setStyle(Paint.Style.FILL);
    pressPaint.setColor(pressColor);
    pressPaint.setAlpha(0);
    pressPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    setDrawingCacheEnabled(true);
    setWillNotDraw(false);
}
 
Example 7
Project: airgram   File: MultiColorPicker.java   View Source Code Vote up 5 votes
private void init() {

        colorPointerPaint = new Paint();
        colorPointerPaint.setStyle(Style.STROKE);
        colorPointerPaint.setStrokeWidth(2f);
        colorPointerPaint.setARGB(128, 0, 0, 0);

        valuePointerPaint = new Paint();
        valuePointerPaint.setStyle(Style.STROKE);
        valuePointerPaint.setStrokeWidth(2f);

        valuePointerArrowPaint = new Paint();

        colorWheelPaint = new Paint();
        colorWheelPaint.setAntiAlias(true);
        colorWheelPaint.setDither(true);

        valueSliderPaint = new Paint();
        valueSliderPaint.setAntiAlias(true);
        valueSliderPaint.setDither(true);

        colorViewPaint = new Paint();
        colorViewPaint.setAntiAlias(true);

        colorViewPath = new Path();
        valueSliderPath = new Path();
        arrowPointerPath = new Path();

        outerWheelRect = new RectF();
        innerWheelRect = new RectF();

        colorPointerCoords = new RectF();

    }
 
Example 8
Project: SimpleUILauncher   File: FolderIcon.java   View Source Code Vote up 5 votes
public void drawBackground(Canvas canvas, Paint paint) {
    canvas.save();
    canvas.translate(getOffsetX(), getOffsetY());
    paint.reset();
    paint.setStyle(Paint.Style.FILL);//充满
    paint.setColor(Color.LTGRAY);
    paint.setAntiAlias(true);
    paint.setAlpha(100);
    RectF oval3 = new RectF(0, 0, mBackground.previewSize, mBackground.previewSize);
    canvas.drawRoundRect(oval3, 40, 40,paint);
    canvas.restore();

}
 
Example 9
Project: ListItemView   File: CircleTransform.java   View Source Code Vote up 5 votes
@Override
public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());

    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
    if (squaredBitmap != source) {
        source.recycle();
    }

    Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP,
            BitmapShader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setAntiAlias(true);

    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);

    squaredBitmap.recycle();
    return bitmap;
}
 
Example 10
Project: KTalk   File: EaseImageView.java   View Source Code Vote up 5 votes
/**
 * draw Rounded Rectangle
 *
 * @param canvas
 * @param bitmap
 */
private void drawDrawable(Canvas canvas, Bitmap bitmap) {
    Paint paint = new Paint();
    paint.setColor(0xffffffff);
    paint.setAntiAlias(true); //smooths out the edges of what is being drawn
    PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
    // set flags
    int saveFlags = Canvas.MATRIX_SAVE_FLAG
            | Canvas.CLIP_SAVE_FLAG
            | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
            | Canvas.FULL_COLOR_LAYER_SAVE_FLAG
            | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
    canvas.saveLayer(0, 0, width, height, null, saveFlags);

    if (shapeType == 1) {
        canvas.drawCircle(width / 2, height / 2, width / 2 - 1, paint);
    } else if (shapeType == 2) {
        RectF rectf = new RectF(1, 1, getWidth() - 1, getHeight() - 1);
        canvas.drawRoundRect(rectf, radius + 1, radius + 1, paint);
    }

    paint.setXfermode(xfermode);

    float scaleWidth = ((float) getWidth()) / bitmap.getWidth();
    float scaleHeight = ((float) getHeight()) / bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);

    //bitmap scale
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

    canvas.drawBitmap(bitmap, 0, 0, paint);
    canvas.restore();
}
 
Example 11
Project: goRefresh   File: MulRingProgressBar.java   View Source Code Vote up 5 votes
public MulRingProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.context = context;
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.MulRingProgressBar);
    mBallColor = typedArray.getColor(R.styleable.MulRingProgressBar_progress_ball_color, mBallColor);
    mRingColor = typedArray.getColor(R.styleable.MulRingProgressBar_progress_ring_color, mRingColor);
    mBallRadius = typedArray.getDimension(R.styleable.MulRingProgressBar_progress_ball_radius, mBallRadius);
    mRingRadius = typedArray.getDimension(R.styleable.MulRingProgressBar_progress_ring_radius, mRingRadius);
    mDuration = typedArray.getInteger(R.styleable.MulRingProgressBar_progress_duration, mDuration);
    increment = typedArray.getFloat(R.styleable.MulRingProgressBar_progress_increment, increment);
    mCount = typedArray.getInteger(R.styleable.MulRingProgressBar_progress_count, mCount);
    typedArray.recycle();

    mList = new ArrayList<>();

    for (int i = mCount; i > 0; i--) {
        ProgressBean pb = new ProgressBean();
        pb.setmCurrentAngle(0);
        pb.setmBallRadius(mBallRadius + increment * i);
        pb.setDuration(mDuration - (mCount - i) * delay);
        pb.setAnimator(initAnimatior(pb));
        mList.add(pb);
    }

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);


}
 
Example 12
Project: tuxguitar   File: TGPopwindowView.java   View Source Code Vote up 5 votes
private void init() {
    paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
    paint.setTextSize(48.0f);
    paint.setTextAlign(Paint.Align.CENTER);
}
 
Example 13
Project: buildAPKsSamples   File: CubeWallpaper2.java   View Source Code Vote up 5 votes
CubeEngine() {
    // Create a Paint to draw the lines for our cube
    final Paint paint = mPaint;
    paint.setColor(0xffffffff);
    paint.setAntiAlias(true);
    paint.setStrokeWidth(2);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStyle(Paint.Style.STROKE);

    mStartTime = SystemClock.elapsedRealtime();

    mPrefs = CubeWallpaper2.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
    mPrefs.registerOnSharedPreferenceChangeListener(this);
    onSharedPreferenceChanged(mPrefs, null);
}
 
Example 14
Project: TensorflowAndroidDemo   File: ObjectTracker.java   View Source Code Vote up 5 votes
private void drawHistoryPoint(final Canvas canvas, final float startX, final float startY) {
  final Paint p = new Paint();
  p.setAntiAlias(false);
  p.setTypeface(Typeface.SERIF);

  p.setColor(Color.RED);
  p.setStrokeWidth(2.0f);

  // Draw the center circle.
  p.setColor(Color.GREEN);
  canvas.drawCircle(startX, startY, 3.0f, p);

  p.setColor(Color.RED);

  // Iterate through in backwards order.
  synchronized (debugHistory) {
    final int numPoints = debugHistory.size();
    float lastX = startX;
    float lastY = startY;
    for (int keypointNum = 0; keypointNum < numPoints; ++keypointNum) {
      final PointF delta = debugHistory.get(numPoints - keypointNum - 1);
      final float newX = lastX + delta.x;
      final float newY = lastY + delta.y;
      canvas.drawLine(lastX, lastY, newX, newY, p);
      lastX = newX;
      lastY = newY;
    }
  }
}
 
Example 15
Project: Alexa-Voice-Service   File: recorderView.java   View Source Code Vote up 5 votes
private void init(){
    backgroundPaint = new Paint();
    backgroundPaint.setColor(0x66000000);
    backgroundPaint.setStyle(Paint.Style.FILL);

    wavepaint = new Paint();
    wavepaint.setColor(0xff3F51B5);
    wavepaint.setAntiAlias(true);
    wavepaint.setStyle(Paint.Style.FILL);
}
 
Example 16
Project: letv   File: RoundImageView.java   View Source Code Vote up 5 votes
private void drawCircleBorder(Canvas canvas, int radius, int color) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    paint.setColor(color);
    paint.setStyle(Style.STROKE);
    paint.setStrokeWidth((float) this.mBorderThickness);
    canvas.drawCircle((float) (this.defaultWidth / 2), (float) (this.defaultHeight / 2), (float) radius, paint);
}
 
Example 17
Project: custode   File: RoundedContactBadge.java   View Source Code Vote up 4 votes
private void init() {
    whitePaint = new Paint();
    whitePaint.setColor(ContextCompat.getColor(getContext(), android.R.color.white));
    whitePaint.setAntiAlias(true);
}
 
Example 18
Project: Rxjava2.0Demo   File: PathsDrawable.java   View Source Code Vote up 4 votes
public PathsDrawable() {
    mPaint = new Paint();
    mPaint.setColor(0xff11bbff);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setAntiAlias(true);
}
 
Example 19
Project: memento-app   File: ImageHelper.java   View Source Code Vote up 4 votes
public static Bitmap drawFaceRectanglesOnBitmap(
        Bitmap originalBitmap, Face[] faces, boolean drawLandmarks) {
    Bitmap bitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.GREEN);
    int stokeWidth = Math.max(originalBitmap.getWidth(), originalBitmap.getHeight()) / 100;
    if (stokeWidth == 0) {
        stokeWidth = 1;
    }
    paint.setStrokeWidth(stokeWidth);

    if (faces != null) {
        for (Face face : faces) {
            FaceRectangle faceRectangle =
                    calculateFaceRectangle(bitmap, face.faceRectangle, FACE_RECT_SCALE_RATIO);

            canvas.drawRect(
                    faceRectangle.left,
                    faceRectangle.top,
                    faceRectangle.left + faceRectangle.width,
                    faceRectangle.top + faceRectangle.height,
                    paint);

            if (drawLandmarks) {
                int radius = face.faceRectangle.width / 30;
                if (radius == 0) {
                    radius = 1;
                }
                paint.setStyle(Paint.Style.FILL);
                paint.setStrokeWidth(radius);

                canvas.drawCircle(
                        (float) face.faceLandmarks.pupilLeft.x,
                        (float) face.faceLandmarks.pupilLeft.y,
                        radius,
                        paint);

                canvas.drawCircle(
                        (float) face.faceLandmarks.pupilRight.x,
                        (float) face.faceLandmarks.pupilRight.y,
                        radius,
                        paint);

                canvas.drawCircle(
                        (float) face.faceLandmarks.noseTip.x,
                        (float) face.faceLandmarks.noseTip.y,
                        radius,
                        paint);

                canvas.drawCircle(
                        (float) face.faceLandmarks.mouthLeft.x,
                        (float) face.faceLandmarks.mouthLeft.y,
                        radius,
                        paint);

                canvas.drawCircle(
                        (float) face.faceLandmarks.mouthRight.x,
                        (float) face.faceLandmarks.mouthRight.y,
                        radius,
                        paint);

                paint.setStyle(Paint.Style.STROKE);
                paint.setStrokeWidth(stokeWidth);
            }
        }
    }

    return bitmap;
}
 
Example 20
Project: Hotspot-master-devp   File: PagerSlidingTabStrip.java   View Source Code Vote up 4 votes
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        setFillViewport(true);
        setWillNotDraw(false);// 防止onDraw方法不执行

        tabsContainer = new LinearLayout(context);
        tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
        tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        addView(tabsContainer);

        //设置默认值
        DisplayMetrics dm = getResources().getDisplayMetrics();
        scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
        indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
        underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
        dividerPaddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPaddingTopBottom, dm);
        tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
        dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
        tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

        // get system attrs (android:textSize and android:textColor)
        TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
        tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
        tabTextColor = a.getColor(1, tabTextColor);
        a.recycle();

        // get custom attrs

        a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

        indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
        underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
        dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
        indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight);
        underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight);
        dividerPaddingTopBottom = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPaddingTopBottom, dividerPaddingTopBottom);
        tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
        tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId);
        shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
        scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
        textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
        selectedTabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextSelectedColor, selectedTabTextColor);
        zoomMax = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsScaleZoomMax, zoomMax);
        smoothScrollWhenClickTab = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsSmoothScrollWhenClickTab, smoothScrollWhenClickTab);
        //宽为match_parent ,指示器的宽需手动计算的问题,这个属性设置为true,则指示器的位置和字体的宽一样
//        indicatorWrap = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsIndicatorWrap, indicatorWrap);
        a.recycle();

        rectPaint = new Paint();
        rectPaint.setAntiAlias(true);
        rectPaint.setStyle(Style.FILL);

        dividerPaint = new Paint();
        dividerPaint.setAntiAlias(true);
        dividerPaint.setStrokeWidth(dividerWidth);

        defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
        matchParentTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

        if (locale == null) {
            locale = getResources().getConfiguration().locale;
        }
        pageListener = new PageListener();

        mPaintTabText.setAntiAlias(true);
    }