Java Code Examples for android.graphics.Canvas#drawRoundRect()

The following examples show how to use android.graphics.Canvas#drawRoundRect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RectProgress.java    From IOS11RectProgress with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onDraw(Canvas canvas) {
        int canvasWidth = canvas.getWidth();
        int canvasHeight = canvas.getHeight();
        int layerId = canvas.saveLayer(0, 0, canvasWidth, canvasHeight, null, Canvas.ALL_SAVE_FLAG);
        {
            bgPaint.setColor(bgColor);
            // draw the background of progress
            canvas.drawRoundRect(bgRect, rectRadius, rectRadius, bgPaint);
            // draw progress
            canvas.drawRect(progressRect, progressPaint);
            bgPaint.setXfermode(null);
            if (bitmap != null) {
                //draw icon
                canvas.drawBitmap(bitmap, srcRect, dstRect, bgPaint);
            }
        }
        canvas.restoreToCount(layerId);
        // TODO: 弄明白为什么在xml预览中,canvas.restoreToCount
        // TODO: 会导致后续的canvas对象为空 但canvas.restore方法则不会导致这个问题
//        canvas.restore();
//        canvas.save();

    }
 
Example 2
Source File: ENScrollView.java    From ENViews with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.save();
    canvas.translate(mFraction * mViewTranslationX, 0);
    canvas.drawRoundRect(mRectF, mCircleRadius, mCircleRadius, mBgPaint);   //嗷~ 在这画背景线
    mDstPath.reset();
    mPathMeasure.getSegment(0 ,mPathLength / 2 * mFraction, mDstPath, true);
    canvas.drawPath(mDstPath, mPaint);  //嗷~ 在这画上半圈
    mDstPath.reset();
    mPathMeasure.getSegment(mPathLength - mPathLength / 2 * mFraction ,mPathLength, mDstPath, true);
    canvas.drawPath(mDstPath, mPaint);  //嗷~ 在这画下半圈
    mColorPaint.setColor(mCurrentColor);
    if (mFraction <= 0.8 && mFraction > 0.2) {  //嗷~ 在这画球
        canvas.drawCircle(mCenterX - mCircleRadius + 2 * mCircleRadius * mFraction , mCenterY , mCircleRadius / 6 / 0.6f * (mFraction - 0.2f) , mColorPaint);
    } else if (mFraction > 0.8) {
        canvas.drawCircle(mCenterX - mCircleRadius + 2 * mCircleRadius * mFraction , mCenterY , mCircleRadius / 6 , mColorPaint);
    }
    canvas.restore();
}
 
Example 3
Source File: ToggleButton.java    From DMusic with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    float rectRadius = mHeight / 2f;
    mRect.set(0, 0, mWidth, mHeight);
    mRectF.set(mRect);
    canvas.drawRoundRect(mRectF, rectRadius, rectRadius, mIsOpen ? mPaintTrack : mPaintPadding);

    mRect.set((int) mPadding, (int) mPadding, (int) (mWidth - mPadding), (int) (mHeight - mPadding));
    mRectF.set(mRect);
    canvas.drawRoundRect(mRectF, rectRadius, rectRadius, mPaintTrack);

    float c0 = mHeight / 2;
    float c1 = mWidth - mHeight / 2;
    float start = !mIsOpen ? c1 : c0;
    float end = mIsOpen ? c1 : c0;
    float offsetX = start + (end - start) * mFactor; // 通过属性动画因子,计算此瞬间圆心的横坐标

    canvas.drawCircle(offsetX, mHeight / 2, mHeight / 2 - mPadding, mPaintShader);
}
 
Example 4
Source File: ColorPickerView.java    From YCCustomText with Apache License 2.0 6 votes vote down vote up
private void createColorTableBitmap() {

        Canvas c = new Canvas(bitmapForColor);
        RectF rf = new RectF(0, 0, bitmapForColor.getWidth(), bitmapForColor.getHeight());

        // 圆角大小
        int r;
        if (orientation == Orientation.HORIZONTAL) {
            r = bitmapForColor.getHeight() / 2;
        } else {
            r = bitmapForColor.getWidth() / 2;
        }
        // 先绘制黑色背景,否则有 alpha 时绘制不正常
        paint.setColor(Color.BLACK);
        c.drawRoundRect(rf, r, r, paint);

        paint.setShader(linearGradient);
        c.drawRoundRect(rf, r, r, paint);
        paint.setShader(null);

        needReDrawColorTable = false;
    }
 
Example 5
Source File: RoundedRectangleBitmapTextureAtlasSourceDecoratorShape.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void onDecorateBitmap(final Canvas pCanvas, final Paint pPaint, final TextureAtlasSourceDecoratorOptions pDecoratorOptions) {
	final float left = pDecoratorOptions.getInsetLeft();
	final float top = pDecoratorOptions.getInsetTop();
	final float right = pCanvas.getWidth() - pDecoratorOptions.getInsetRight();
	final float bottom = pCanvas.getHeight() - pDecoratorOptions.getInsetBottom();

	this.mRectF.set(left, top, right, bottom);

	pCanvas.drawRoundRect(this.mRectF, this.mCornerRadiusX, this.mCornerRadiusY, pPaint);
}
 
Example 6
Source File: RectangularShape.java    From hintcase with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void drawRoundRectAfterLollipop(Canvas canvas) {
    canvas.drawRoundRect(getCenterX() - (currentWidth / 2),
            getCenterY() - (currentHeight / 2),
            getCenterX() + (currentWidth / 2),
            getCenterY() + (currentHeight / 2),
            10f,
            10f,
            getShapePaint());
}
 
Example 7
Source File: ImageHelper.java    From FrostyBackgroundTestApp with Apache License 2.0 5 votes vote down vote up
public static Bitmap getRoundedCornerAndLightenBitmap(Bitmap bitmap, int cornerRadiusInPixels, boolean captureCircle) {
    Bitmap output = Bitmap.createBitmap(
            bitmap.getWidth(),
            bitmap.getHeight(),
            Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(output);

    final int color = 0xffffffff;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0,
            0,
            bitmap.getWidth(),
            bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = cornerRadiusInPixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    if (captureCircle) {
        canvas.drawCircle(rectF.centerX(),
                rectF.centerY(),
                bitmap.getWidth() / 2,
                paint);
    } else {
        canvas.drawRoundRect(rectF,
                roundPx,
                roundPx,
                paint);
    }

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    ColorFilter filter = new LightingColorFilter(0xFFFFFFFF, 0x00222222); // lighten
    //ColorFilter filter = new LightingColorFilter(0xFF7F7F7F, 0x00000000);    // darken
    paint.setColorFilter(filter);
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
 
Example 8
Source File: MaterialCheckbox.java    From FilePicker with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isChecked()) {
        paint.reset();
        paint.setAntiAlias(true);
        bounds.set(minDim / 10, minDim / 10, minDim - (minDim / 10), minDim - (minDim / 10));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            paint.setColor(getResources().getColor(R.color.colorAccent, context.getTheme()));
        } else {
            paint.setColor(getResources().getColor(R.color.colorAccent));
        }
        canvas.drawRoundRect(bounds, minDim / 8, minDim / 8, paint);

        paint.setColor(Color.parseColor("#FFFFFF"));
        paint.setStrokeWidth(minDim / 10);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(Paint.Join.BEVEL);
        canvas.drawPath(tick, paint);
    } else {
        paint.reset();
        paint.setAntiAlias(true);
        bounds.set(minDim / 10, minDim / 10, minDim - (minDim / 10), minDim - (minDim / 10));
        paint.setColor(Color.parseColor("#C1C1C1"));
        canvas.drawRoundRect(bounds, minDim / 8, minDim / 8, paint);

        bounds.set(minDim / 5, minDim / 5, minDim - (minDim / 5), minDim - (minDim / 5));
        paint.setColor(Color.parseColor("#FFFFFF"));
        canvas.drawRect(bounds, paint);
    }
}
 
Example 9
Source File: RoundedCornersTransformation.java    From AcgClub with MIT License 5 votes vote down vote up
private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
  canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
      paint);
  canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
      paint);
  canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
}
 
Example 10
Source File: ButtonProgressBar.java    From ButtonProgressBar with Apache License 2.0 5 votes vote down vote up
/**
 * Draw mProgress on view based on mLoaderType.
 * @param canvas - view canvas object
 */
public void onDrawProgress(Canvas canvas) {
    RectF bgRectf = new RectF(topX, topY, canvas.getWidth(), canvas.getHeight());
    canvas.drawRoundRect(bgRectf, mCornerRadius, mCornerRadius, mBackgroundPaint);
    float progressPoint = (((float) canvas.getWidth()/ MAX) * mProgress);
    RectF progRect = new RectF(topX, topY, progressPoint, canvas.getHeight());
    canvas.drawRoundRect(progRect, mCornerRadius, mCornerRadius, mProgressPaint);
}
 
Example 11
Source File: RoundedCornersTransformation.java    From AcgClub with MIT License 5 votes vote down vote up
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
    float bottom) {
  canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
      radius, paint);
  canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom),
      radius, radius, paint);
  canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
  canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
}
 
Example 12
Source File: GridTextMarker.java    From InteractiveChart with Apache License 2.0 5 votes vote down vote up
@Override public void onMarkerViewDraw(Canvas canvas, String[] markerText) {
  canvas.drawRoundRect(markerInsets, attribute.markerBorderRadius, attribute.markerBorderRadius,
      markerBorderPaint);

  canvas.drawText(markerText[1],
      markerInsets.left + markerInsets.width() / 2,
      markerInsets.top + (markerInsets.height() + textRect.height()) / 2,
      markerTextPaint);
}
 
Example 13
Source File: PieChartLableView.java    From OXChart with Apache License 2.0 4 votes vote down vote up
/**绘制图表*/
    @Override
    public void drawChart(Canvas canvas) {

        int topY = top + mMoveLen;

        paintLabel.setTextSize(textSize);
        int lableH =(int) FontUtil.getFontHeight(paintLabel);
        int lableL =(int) FontUtil.getFontLeading(paintLabel);

        paint.setStyle(Paint.Style.FILL);

        int index = -1;
        for(int i = 0; i < dataList.size(); i++){
            PieChartBean bean = dataList.get(i);
            if(bean.getNum() == 0 && !showZeroPart){
                continue;
            }
            index++;
            paint.setARGB(255, arrColorRgb[index%arrColorRgb.length][0], arrColorRgb[index%arrColorRgb.length][1], arrColorRgb[index%arrColorRgb.length][2]);
            paintLabel.setARGB(255, arrColorRgb[index%arrColorRgb.length][0], arrColorRgb[index%arrColorRgb.length][1], arrColorRgb[index%arrColorRgb.length][2]);

            int rectTop = topY+(oneLableHeight-rectH)/2;
            RectF rect = new RectF(leftSpace, rectTop, leftSpace+rectW, rectTop+rectH);
            canvas.drawRoundRect(rect, rectRaidus, rectRaidus, paint);


            if(textColor!=0) {
                paintLabel.setColor(textColor);
            }
            rectTop = topY+(oneLableHeight-lableH)/2;
            canvas.drawText(bean.getName(), leftSpace+rectW+leftSpace , rectTop+lableL , paintLabel);
            float textW = FontUtil.getFontlength(paintLabel, bean.getName());
            /**5、绘制指示标签*/
            if(MODUL_LABLE == tagModul){
                String tagText = "";
                if (tagType == PieChartLayout.TAG_TYPE.TYPE_NUM) {
                    tagText = bean.getNum() + "";
                } else if (tagType == PieChartLayout.TAG_TYPE.TYPE_PERCENT) {
                    DecimalFormat decimalFormat = new DecimalFormat("0.0%");
                    tagText = decimalFormat.format(((float) bean.getNum() / (float) total));
                }
                float tagW = FontUtil.getFontlength(paintLabel, tagText);
                canvas.drawText(tagText, getMeasuredWidth()-tagW- DensityUtil.dip2px(getContext(),3), rectTop+lableL , paintLabel);

            /*    DashPathEffect dashPathEffect = new DashPathEffect(new float[]{8,10,8,10}, 0);
                paint.setColor(Color.RED);
//                paint.setPathEffect(dashPathEffect);
                paint.setStrokeWidth(4);
                Path path = new Path();
                path.moveTo(leftSpace+rectW+leftSpace+textW, rectTop);
                path.lineTo(getMeasuredWidth()-tagW- DensityUtil.dip2px(getContext(),3), rectTop);
                LogUtil.i(TAG, "绘制虚线"+path);
                canvas.drawPath(path,paint);*/
            }
            topY += oneLableHeight + rectSpace;
        }

    }
 
Example 14
Source File: EasyCountDownTextureView.java    From EasyCountDownTextureView with Apache License 2.0 4 votes vote down vote up
private void drawTimeAndBackground(@NonNull final Canvas canvas,
                                   @NonNull final String hour,
                                   @NonNull final String minute,
                                   @NonNull final String second) {
    // background
    canvas.save();
    canvas.translate(paddingLeft, paddingTop);
    canvas.drawRoundRect(backgroundRectF, rectRadius, rectRadius, backgroundPaint);
    // border
    this.drawRectBorder(canvas, backgroundRectF, rectRadius, rectBorderPaint);
    canvas.drawText(hour, backgroundRectF.centerX(), timePaintBaseLine, timePaint);
    canvas.restore();

    // colon
    canvas.save();
    canvas.translate(firstTranslateColonX, paddingTop);
    canvas.drawText(COLON, 0, timePaintBaseLineFixed, colonPaint);
    canvas.restore();

    // background
    canvas.save();
    canvas.translate(firstTranslateX, paddingTop);
    canvas.drawRoundRect(backgroundRectF, rectRadius, rectRadius, backgroundPaint);
    // border
    this.drawRectBorder(canvas, backgroundRectF, rectRadius, rectBorderPaint);
    canvas.drawText(minute, backgroundRectF.centerX(), timePaintBaseLine, timePaint);
    canvas.restore();

    // colon
    canvas.save();
    canvas.translate(secondTranslateColonX, paddingTop);
    canvas.drawText(COLON, 0, timePaintBaseLineFixed, colonPaint);
    canvas.restore();

    // background
    canvas.save();
    canvas.translate(secondTranslateX, paddingTop);
    canvas.drawRoundRect(backgroundRectF, rectRadius, rectRadius, backgroundPaint);
    // border
    this.drawRectBorder(canvas, backgroundRectF, rectRadius, rectBorderPaint);
    canvas.drawText(second, backgroundRectF.centerX(), timePaintBaseLine, timePaint);
    canvas.restore();
}
 
Example 15
Source File: RoundedCornersTransformation.java    From AcgClub with MIT License 4 votes vote down vote up
private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
  canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
      paint);
  canvas.drawRect(new RectF(margin, margin, right, bottom - radius), paint);
}
 
Example 16
Source File: RoundedCornersTransformation.java    From AcgClub with MIT License 4 votes vote down vote up
private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
  canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
      radius, paint);
  canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
  canvas.drawRect(new RectF(right - radius, margin, right, bottom - radius), paint);
}
 
Example 17
Source File: RoundedImageView.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
public Bitmap getRoundedCornerBitmap(Context context, Bitmap input,
                                     int pixels, int w, int h, boolean squareTL, boolean squareTR,
                                     boolean squareBL, boolean squareBR) {

    Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final float densityMultiplier = context.getResources()
            .getDisplayMetrics().density;

    final int color = 0xff424242;

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, w, h);
    final RectF rectF = new RectF(rect);

    // make sure that our rounded corner is scaled appropriately
    final float roundPx = pixels * densityMultiplier;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    // draw rectangles over the corners we want to be square
    if (squareTL) {
        canvas.drawRect(0, 0, w / 2, h / 2, paint);
    }
    if (squareTR) {
        canvas.drawRect(w / 2, 0, w, h / 2, paint);
    }
    if (squareBL) {
        canvas.drawRect(0, h / 2, w / 2, h, paint);
    }
    if (squareBR) {
        canvas.drawRect(w / 2, h / 2, w, h, paint);
    }

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(input, 0, 0, paint);

    return output;
}
 
Example 18
Source File: IndexFastScrollRecyclerSection.java    From 920-text-editor-v2 with Apache License 2.0 4 votes vote down vote up
public void draw(Canvas canvas) {
    Paint indexbarPaint = new Paint();
    indexbarPaint.setColor(Color.parseColor(indexbarBackgroudColor));
    indexbarPaint.setAlpha(indexbarBackgroudAlpha);
    indexbarPaint.setAntiAlias(true);
    canvas.drawRoundRect(mIndexbarRect, setIndexBarCornerRadius * mDensity, setIndexBarCornerRadius * mDensity, indexbarPaint);

    if (mSections != null && mSections.length > 0) {
        // Preview is shown when mCurrentSection is set
        if (mCurrentSection >= 0) {
            Paint previewPaint = new Paint();
            previewPaint.setColor(Color.BLACK);
            previewPaint.setAlpha(96);
            previewPaint.setAntiAlias(true);
            previewPaint.setShadowLayer(3, 0, 0, Color.argb(64, 0, 0, 0));

            Paint previewTextPaint = new Paint();
            previewTextPaint.setColor(Color.WHITE);
            previewTextPaint.setAntiAlias(true);
            previewTextPaint.setTextSize(50 * mScaledDensity);
            previewTextPaint.setTypeface(setTypeface);

            float previewTextWidth = previewTextPaint.measureText(mSections[mCurrentSection]);
            float previewSize = 2 * mPreviewPadding + previewTextPaint.descent() - previewTextPaint.ascent();
            RectF previewRect = new RectF((mListViewWidth - previewSize) / 2
                    , (mListViewHeight - previewSize) / 2
                    , (mListViewWidth - previewSize) / 2 + previewSize
                    , (mListViewHeight - previewSize) / 2 + previewSize);

            canvas.drawRoundRect(previewRect, 5 * mDensity, 5 * mDensity, previewPaint);
            canvas.drawText(mSections[mCurrentSection], previewRect.left + (previewSize - previewTextWidth) / 2 - 1
                    , previewRect.top + mPreviewPadding - previewTextPaint.ascent() + 1, previewTextPaint);
            fade(300);
        }

        Paint indexPaint = new Paint();
        indexPaint.setColor(Color.parseColor(indexbarTextColor));
        indexPaint.setAntiAlias(true);
        indexPaint.setTextSize(setIndexTextSize * mScaledDensity);
        indexPaint.setTypeface(setTypeface);

        float sectionHeight = (mIndexbarRect.height() - 2 * mIndexbarMargin) / mSections.length;
        float paddingTop = (sectionHeight - (indexPaint.descent() - indexPaint.ascent())) / 2;
        for (int i = 0; i < mSections.length; i++) {
            float paddingLeft = (mIndexbarWidth - indexPaint.measureText(mSections[i])) / 2;
            canvas.drawText(mSections[i], mIndexbarRect.left + paddingLeft
                    , mIndexbarRect.top + mIndexbarMargin + sectionHeight * i + paddingTop - indexPaint.ascent(), indexPaint);
        }
    }
}
 
Example 19
Source File: LinkedView.java    From DS4Android with MIT License 4 votes vote down vote up
/**
 * 绘制表结构
 *
 * @param canvas
 */
private void dataView(Canvas canvas) {
    mPaint.setColor(Color.BLUE);
    mPaint.setStyle(Paint.Style.FILL);
    mPath.reset();
    for (int i = 0; i < mArrayBoxes.size(); i++) {
        LinkedNode box = mArrayBoxes.get(i);

        mPaint.setColor(box.color);
        canvas.drawRoundRect(
                box.x, box.y, box.x + Cons.BOX_WIDTH, box.y + Cons.BOX_HEIGHT,
                BOX_RADIUS, BOX_RADIUS, mPaint);

        mPath.moveTo(box.x, box.y);
        mPath.rCubicTo(Cons.BOX_WIDTH / 2, Cons.BOX_HEIGHT / 2,
                Cons.BOX_WIDTH / 2, Cons.BOX_HEIGHT / 2, Cons.BOX_WIDTH, 0);

        if (i < mArrayBoxes.size() - 1 ) {
            LinkedNode box_next = mArrayBoxes.get(i + 1);
            LinkedNode box_now = mArrayBoxes.get(i);

            if (i % LINE_ITEM_NUM == LINE_ITEM_NUM - 1) {//边界情况
                mPath.rLineTo(0, Cons.BOX_HEIGHT);
                mPath.lineTo(box_next.x + Cons.BOX_WIDTH, box_next.y);
                mPath.rLineTo(Cons.ARROW_DX, -Cons.ARROW_DX);

                mPath.moveTo(box_next.x, box_next.y);
                mPath.lineTo(box_now.x, box_now.y+Cons.BOX_HEIGHT);
                mPath.rLineTo(-Cons.ARROW_DX, Cons.ARROW_DX);

            } else {
                mPath.rLineTo(0, Cons.BOX_HEIGHT / 2.2f);
                mPath.lineTo(box_next.x+Cons.BOX_WIDTH * 0.2f, box_next.y + Cons.BOX_HEIGHT / 2f);
                mPath.rLineTo(-Cons.ARROW_DX, -Cons.ARROW_DX);

                mPath.moveTo(box_next.x, box_next.y);
                mPath.rLineTo(0, Cons.BOX_HEIGHT / 1.2f);
                mPath.lineTo(box_now.x + Cons.BOX_WIDTH * 0.8f, box_now.y + Cons.BOX_HEIGHT * 0.8f);
                mPath.rLineTo(Cons.ARROW_DX, Cons.ARROW_DX);
            }
        }
        canvas.drawPath(mPath, mPathPaint);

        canvas.drawText(box.index + "",
                box.x + Cons.BOX_WIDTH / 2,
                box.y + 3 * OFFSET_OF_TXT_Y, mTxtPaint);

        canvas.drawText(box.data + "",
                box.x + Cons.BOX_WIDTH / 2,
                box.y + Cons.BOX_HEIGHT / 2 + 3 * OFFSET_OF_TXT_Y, mTxtPaint);
    }
}
 
Example 20
Source File: BitmapUtils.java    From BigApp_Discuz_Android with Apache License 2.0 3 votes vote down vote up
/**
 * 获得圆角图片的方法
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap

            .getHeight(), Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;

    final Paint paint = new Paint();

    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);

    canvas.drawARGB(0, 0, 0, 0);

    paint.setColor(color);

    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;

}