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

The following are Jave code examples for showing how to use setDither() 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: AwesomeQRCode   File: AwesomeQRCode.java   View Source Code Vote up 6 votes
private static void scaleBitmap(Bitmap src, Bitmap dst) {
    Paint cPaint = new Paint();
    cPaint.setAntiAlias(true);
    cPaint.setDither(true);
    cPaint.setFilterBitmap(true);

    float ratioX = dst.getWidth() / (float) src.getWidth();
    float ratioY = dst.getHeight() / (float) src.getHeight();
    float middleX = dst.getWidth() * 0.5f;
    float middleY = dst.getHeight() * 0.5f;

    Matrix scaleMatrix = new Matrix();
    scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
    Canvas canvas = new Canvas(dst);
    canvas.setMatrix(scaleMatrix);
    canvas.drawBitmap(src, middleX - src.getWidth() / 2,
            middleY - src.getHeight() / 2, cPaint);
}
 
Example 2
Project: YiZhi   File: HistoryChartView.java   View Source Code Vote up 6 votes
private void initPaint() {
    linePaint = new Paint();
    linePaint.setStyle(Paint.Style.STROKE);
    linePaint.setAntiAlias(true);
    linePaint.setColor(lineColor);
    linePaint.setDither(true);
    linePaint.setStrokeWidth(lineStrokeWidth);

    roomTempPaint = new Paint();
    roomTempPaint.setStyle(Paint.Style.STROKE);
    roomTempPaint.setAntiAlias(true);
    roomTempPaint.setColor(roomTempLineColor);
    roomTempPaint.setDither(true);
    roomTempPaint.setStrokeWidth(dataStrokeWidth);

    targetTempPaint = new Paint();
    targetTempPaint.setStyle(Paint.Style.STROKE);
    targetTempPaint.setAntiAlias(true);
    targetTempPaint.setColor(targetTempLineColor);
    targetTempPaint.setDither(true);
    targetTempPaint.setStrokeWidth(dataStrokeWidth);

    mBmpPaint = new Paint();
}
 
Example 3
Project: QuranAndroid   File: QuranPageReadActivity.java   View Source Code Vote up 6 votes
/**
 * Function to draw number in the bitmap
 *
 * @param number Number to draw
 * @return the new bitmap after draw
 */
public Bitmap drawNumbers(String number) {
    float fontAndPadding = getResources().getDimension(R.dimen.draw_number);
    Paint paint = new Paint();
    paint.setTextSize(fontAndPadding);
    paint.setColor(Color.WHITE);
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    paint.setFakeBoldText(true);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_repeat);
    Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    canvas.drawText(number, bitmap.getWidth() - fontAndPadding, fontAndPadding, paint);
    return mutableBitmap;
}
 
Example 4
Project: VirtualHook   File: ShadowViewDrawable.java   View Source Code Vote up 6 votes
public ShadowViewDrawable(ShadowProperty shadowProperty, int color, float rx, float ry) {
    this.shadowProperty = shadowProperty;
    shadowOffset = this.shadowProperty.getShadowOffset();

    this.rx = rx;
    this.ry = ry;

    paint = new Paint();
    paint.setAntiAlias(true);
    /**
     * 解决旋转时的锯齿问题
     */
    paint.setFilterBitmap(true);
    paint.setDither(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(color);
    /**
     * 设置阴影
     */
    paint.setShadowLayer(shadowProperty.getShadowRadius(), shadowProperty.getShadowDx(), shadowProperty.getShadowDy(), shadowProperty.getShadowColor());

    drawRect = new RectF();
}
 
Example 5
Project: xbot_head   File: FaceOverlayView.java   View Source Code Vote up 6 votes
private void initialize() {
    // We want a green box around the face:
    DisplayMetrics metrics = getResources().getDisplayMetrics();

    int stroke = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, metrics);
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(Color.GREEN);
    mPaint.setStrokeWidth(stroke);
    mPaint.setStyle(Paint.Style.STROKE);

    mTextPaint = new Paint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setDither(true);
    int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, metrics);
    mTextPaint.setTextSize(size);
    mTextPaint.setColor(Color.GREEN);
    mTextPaint.setStyle(Paint.Style.FILL);


}
 
Example 6
Project: PropertyAnimatorDemo   File: MyBezierView.java   View Source Code Vote up 6 votes
private void init(Context context) {
    mTextPaint = new Paint();
    mPaint = new Paint();
    mPath = new Path();
    startPoint = new Point(200, 200);
    endPoint = new Point(800, 800);
    assistPoint = new Point(800, 200);
    // 抗锯齿
    mPaint.setAntiAlias(true);
    // 防抖动
    mPaint.setDither(true);
    //坐标
    mTextPaint.setColor(Color.RED);
    mTextPaint.setTextSize(20);
    mTextPaint.setStrokeWidth(10);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setDither(true);
}
 
Example 7
Project: CoordinateAxisChart   File: CoordinateAxisChart.java   View Source Code Vote up 6 votes
private void init(Context context) {

        setConfig(new ChartConfig(), false);

        axisPaint = new Paint();
        axisPaint.setStrokeWidth(axisWidth);
        axisPaint.setColor(axisColor);
        axisPaint.setAntiAlias(true);
        axisPaint.setStyle(Paint.Style.STROKE);
        axisPaint.setTextSize(coordinateTextSize);

        functionLinePaint = new Paint();
        functionLinePaint.setStrokeWidth(functionLineWidth);
        functionLinePaint.setColor(lineColor);
        functionLinePaint.setAntiAlias(true);
        functionLinePaint.setDither(true);
        functionLinePaint.setStyle(Paint.Style.STROKE);

        pointPaint = new Paint();
        pointPaint.setColor(DEFAULT_SINGLE_POINT_COLOR);
        pointPaint.setStyle(Paint.Style.FILL);
        pointPaint.setAntiAlias(true);

        // prepare an array to cache the split points
        xPointsValues = new PointF[segmentSize];
    }
 
Example 8
Project: DragPointView   File: DragPointViewWindow.java   View Source Code Vote up 6 votes
private void init() {
    mPath = new Path();
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setTextSize(18f);
    mPaint.setColor(colorStretching);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mDragTangentPoint = new PointF[2];
    mCenterTangentPoint = new PointF[2];
    mControlPoint = new PointF();
    mCenterCircle = new PointF();
    mCenterCircleCopy = new PointF();
    mDragCircle = new PointF();
    mDragCircleCopy = new PointF();
}
 
Example 9
Project: BubbleAlert   File: AlertDrawable.java   View Source Code Vote up 5 votes
public AlertDrawable(int outerCircleRadiusDP, int textSizeSP, int cornerArc, String drawText, Context context) {
    mContext = context;

    circleRadius = ScreenUtils.unitToPixels(context, TypedValue.COMPLEX_UNIT_DIP, outerCircleRadiusDP);
    textSize = ScreenUtils.unitToPixels(context, TypedValue.COMPLEX_UNIT_SP, textSizeSP);
    mDrawText = TextUtils.isEmpty(drawText) ? " " : drawText;
    initBitmap(mDrawText);
    mBackGroundPaint = new Paint();
    mBackGroundPaint.setAntiAlias(true);
    mBackGroundPaint.setDither(true);
    mBackGroundPaint.setColor(Color.WHITE);
    mBackGroundPaint.setStyle(Paint.Style.FILL);


    mCircleFillPaint = new Paint();
    mCircleFillPaint.setAntiAlias(true);
    mCircleFillPaint.setDither(true);
    mCircleFillPaint.setColor(ContextCompat.getColor(context, R.color.colorMultiArc));
    mCircleFillPaint.setStyle(Paint.Style.FILL);

    mOuterCircleFillPaint = new Paint();
    mOuterCircleFillPaint.setAntiAlias(true);
    mOuterCircleFillPaint.setDither(true);
    mOuterCircleFillPaint.setColor(Color.WHITE);
    mOuterCircleFillPaint.setStyle(Paint.Style.FILL);
    mOuterCircleFillPaint.setTextSize(textSize);


    borderPath = new Path();
    borderRect = new Rect();

    CornerPathEffect cornerPathEffect = new CornerPathEffect(cornerArc);
    mBackGroundPaint.setPathEffect(cornerPathEffect);

    outerCircleOffset = context.getResources().getInteger(R.integer.outerCircleOffset);
}
 
Example 10
Project: planetcon   File: ColorPicker.java   View Source Code Vote up 5 votes
private void init() {
    mShape = SHAPE_DIAMOND;
    mHueTouch = false;

    mColorInitial = 0;
    mColorHSV = new float[] { 0f, 1f, 1f };
    mHSV = new float[] { 0f, 1f, 1f };
    mXY = new double[] {0, 0};

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

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

    mPointerPaint = new Paint();
    mPointerPaint.setStyle(Style.STROKE);
    mPointerPaint.setStrokeWidth(2f);
    mPointerPaint.setAntiAlias(true);

    mHueRingPaint = new Paint();
    mHueRingPaint.setStyle(Style.STROKE);
    mHueRingPaint.setAntiAlias(true);
    mHueRingPaint.setDither(true);

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

    mHueArrowPath = new Path();
    mTrianglePath = new Path();

    mSquareRect = new RectF();

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // Needed by ComposeShader
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
}
 
Example 11
Project: Tabbar   File: TabBarItem.java   View Source Code Vote up 5 votes
/**
 * Init paint and other draw tools
 */
private void initPaintTools() {

    // init paint
    mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setAntiAlias(true);
    mPaint.setColor(Color.WHITE);

    mArgbEvaluator = new ArgbEvaluator();
}
 
Example 12
Project: CameraKitView   File: FocusView.java   View Source Code Vote up 5 votes
private void init(int size) {
    mSize = size;
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(Color.GREEN);
    mPaint.setStrokeWidth(3);
    mPaint.setStyle(Paint.Style.STROKE);
}
 
Example 13
Project: beyondwords   File: ChangeColorIconWithText.java   View Source Code Vote up 5 votes
/**
 * 在内存中绘制可变色的Icon
 */
private void setupTargetBitmap(int alpha) {
    mBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);
    mCanvas = new Canvas(mBitmap);
    mPaint = new Paint();
    mPaint.setColor(mColor);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setAlpha(alpha);
    mCanvas.drawRect(mIconRect, mPaint);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    mPaint.setAlpha(255);
    mCanvas.drawBitmap(mIconBitmap, null, mIconRect, mPaint);
}
 
Example 14
Project: letv   File: RoundImageView.java   View Source Code Vote up 5 votes
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
    Bitmap squareBitmap;
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    Bitmap bitmap;
    int i;
    if (bmpHeight > bmpWidth) {
        bitmap = bmp;
        i = (bmpHeight - bmpWidth) / 2;
        squareBitmap = Bitmap.createBitmap(bitmap, 0, i, bmpWidth, bmpWidth);
    } else if (bmpHeight < bmpWidth) {
        int x = (bmpWidth - bmpHeight) / 2;
        bitmap = bmp;
        i = 0;
        squareBitmap = Bitmap.createBitmap(bitmap, x, i, bmpHeight, bmpHeight);
    } else {
        squareBitmap = bmp;
    }
    if (squareBitmap.getWidth() == diameter && squareBitmap.getHeight() == diameter) {
        scaledSrcBmp = squareBitmap;
    } else {
        scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);
    }
    Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight());
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle((float) (scaledSrcBmp.getWidth() / 2), (float) (scaledSrcBmp.getHeight() / 2), (float) (scaledSrcBmp.getWidth() / 2), paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
    return output;
}
 
Example 15
Project: jackknife   File: ShadeView.java   View Source Code Vote up 5 votes
private void initPaints() {
    mTextPaint = new Paint();
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setDither(true);
    mTextPaint.getTextBounds(mText, 0, mText.length(), mTextRect);
    mIconPaint = new Paint();
}
 
Example 16
Project: Pocket-Plays-for-Twitch   File: RoundedImageView.java   View Source Code Vote up 5 votes
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
	Bitmap sbmp;
	if(bmp.getWidth() != radius || bmp.getHeight() != radius)
		sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
	else
		sbmp = bmp;
	Bitmap output = Bitmap.createBitmap(sbmp.getWidth(),
			sbmp.getHeight(), Bitmap.Config.ARGB_8888);
	Canvas canvas = new Canvas(output);

	final int color = 0xffa19774;
	final Paint paint = new Paint();
	final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

	paint.setAntiAlias(true);
	paint.setFilterBitmap(true);
	paint.setDither(true);
	canvas.drawARGB(0, 0, 0, 0);
	paint.setColor(Color.parseColor("#BAB399"));
	canvas.drawCircle(sbmp.getWidth() / 2+0.7f, sbmp.getHeight() / 2+0.7f,
			sbmp.getWidth() / 2+0.1f, paint);
	paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
	canvas.drawBitmap(sbmp, rect, rect, paint);


	return output;
}
 
Example 17
Project: Bluetooth_BLE   File: FloatView.java   View Source Code Vote up 5 votes
private void initPaint() {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);//抗锯齿
    paint.setDither(true);//开启防抖动
    paint.setStyle(Paint.Style.STROKE);//设置实心
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(10);
}
 
Example 18
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 19
Project: CommonLibrary   File: RoundImageView.java   View Source Code Vote up 4 votes
/**
 * 获取裁剪后的圆形图片
 *
 * @param radius 半径
 * @param bmp    要被裁减的图片
 */
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;
    // 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图片
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    int squareWidth = 0, squareHeight = 0;
    int x = 0, y = 0;
    Bitmap squareBitmap;
    if (bmpHeight > bmpWidth) {// 高大于宽
        squareWidth = squareHeight = bmpWidth;
        x = 0;
        y = (bmpHeight - bmpWidth) / 2;
        // 截取正方形图片
        squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
    } else if (bmpHeight < bmpWidth) {// 宽大于高
        squareWidth = squareHeight = bmpHeight;
        x = (bmpWidth - bmpHeight) / 2;
        y = 0;
        squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
    } else {
        squareBitmap = bmp;
    }

    if (squareBitmap.getWidth() != diameter || squareBitmap.getHeight() != diameter) {
        scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);

    } else {
        scaledSrcBmp = squareBitmap;
    }
    Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(scaledSrcBmp.getWidth() / 2, scaledSrcBmp.getHeight() / 2, scaledSrcBmp.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
    // 回收资源
    // bmp.recycle();
    // squareBitmap.recycle();
    // scaledSrcBmp.recycle();
    bmp = null;
    squareBitmap = null;
    scaledSrcBmp = null;
    return output;
}
 
Example 20
Project: DaiGo   File: BMapUtil.java   View Source Code Vote up 4 votes
/**
 * 根据原图和变长绘制圆形图片
 * @param source
 * @return
 */
public static Bitmap createCircleImage(Bitmap source, int radius, int i) {
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;
    // 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图片
    int bmpWidth = source.getWidth();
    int bmpHeight = source.getHeight();
    int squareWidth = 0, squareHeight = 0;
    int x = 0, y = 0;
    Bitmap squareBitmap;
    if (bmpHeight > bmpWidth) {// 高大于宽
        squareWidth = squareHeight = bmpWidth;
        x = 0;
        y = (bmpHeight - bmpWidth) / 2;
        // 截取正方形图片
        squareBitmap = Bitmap.createBitmap(source, x, y, squareWidth,
                squareHeight);
    } else if (bmpHeight < bmpWidth) {// 宽大于高
        squareWidth = squareHeight = bmpHeight;
        x = (bmpWidth - bmpHeight) / 2;
        y = 0;
        squareBitmap = Bitmap.createBitmap(source, x, y, squareWidth,
                squareHeight);
    } else {
        squareBitmap = source;
    }
    if (squareBitmap.getWidth() != diameter
            || squareBitmap.getHeight() != diameter) {
        scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter,
                diameter, true);
    } else {
        scaledSrcBmp = squareBitmap;
    }
    Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(),
            scaledSrcBmp.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(),
            scaledSrcBmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(scaledSrcBmp.getWidth() / 2,
            scaledSrcBmp.getHeight() / 2, scaledSrcBmp.getWidth() / 2,
            paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);

    squareBitmap = null;
    scaledSrcBmp = null;
    return createBorderBitmap(output, i);
}