Path addRoundRect - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Path addRoundRect method.

This code example shows how to use the following methods:addRoundRect
			 
			// Create a clipping path with rounded corners 
			if (cornerRadius > 0) {
		        final Rect rect = new Rect(borderSize, borderSize, size + borderSize, size + borderSize);
		        final RectF rectF = new RectF(rect);
				Path path = new Path();
				path.addRoundRect(rectF, (float)cornerRadius, (float)cornerRadius, Path.Direction.CCW);
				canvas.clipPath(path);
			} 
			 
			// Draw the image to the canvas (clipped to the path) and centered 
			int x = borderSize - (tempBitmap.getWidth() - size) / 2;
			int y = borderSize - (tempBitmap.getHeight() - size) / 2;	
			Paint paint = new Paint();
			paint.setDither(dither);
			canvas.drawBitmap(tempBitmap, (float)x, (float)y, paint);
			 
			// We're done with the tempBitmap 
			tempBitmap.recycle();
			tempBitmap = null;
8
CodeRank
This code example shows how to use the following methods:addRoundRect, reset
     */ 
    public RoundRectShape(float x, float y, float width, float height, float rx, float ry) {
        this.mRect = new RectF(x, y, x + width, y + height);
        this.mRX = rx;
        this.mRY = ry;
        mPath = new Path();
        update(); 
    } 
     
    /** 
     * Creates new RoundRectShape shape, copying from specified rounded corner rectangle. 
     * @param rect The specified rounded corner rectangle 
     */ 
    public RoundRectShape(RoundRectShape rect) {
        this(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), rect.getRx(), rect.getRy());
         
        mPath = new Path(rect.mPath);
        mRegion = new Region(rect.mRegion);
    } 
 

7
CodeRank
This code example shows how to use the following methods:addRoundRect, close, lineTo, moveTo, reset
		float lineWidth = 2 * mScaledDensity;
		 
		//背景塗りは線の太さを考慮して少し小さくする 
		rect.inset(lineWidth / 2.5f, lineWidth / 2.5f);
		 
		Path path = new Path();
		path.addRoundRect(rect, 20, 20, Direction.CW);
		path.moveTo(startArrowPosX, rect.bottom);
		path.lineTo(arrowTipPosX, rect.bottom + paddingBottom);
		path.lineTo(endArrowPosX, rect.bottom);
		 
		canvas.save(Canvas.CLIP_SAVE_FLAG);
		canvas.clipPath(path);
		 
		//背景色描画 
		canvas.drawColor(0xffffffff);
		 
		//矢印を接続する部分は縁取りを塗らない 
		rect.inset(-lineWidth / 2.5f, -lineWidth / 2.5f);
		path.reset();

6
CodeRank
This code example shows how to use the following methods:addRect, addRoundRect, setFillType
		innerRect.set(bounds.left + padding, bounds.top + padding, bounds.right - padding, bounds.bottom - padding);
 
		if (radius > 0) {
			float outerRadii[] = new float[8];
			Arrays.fill(outerRadii, radius);
			borderPath = new Path();
			borderPath.addRoundRect(outerRect, outerRadii, Direction.CW);
			borderPath.setFillType(FillType.EVEN_ODD);
			innerPath = new Path();
			innerPath.setFillType(FillType.EVEN_ODD);
			if (radius - padding > 0) {
				float innerRadii[] = new float[8];
				Arrays.fill(innerRadii, radius - padding);
				borderPath.addRoundRect(innerRect, innerRadii, Direction.CW);
				innerPath.addRoundRect(innerRect, innerRadii, Direction.CW);
			} else { 
				borderPath.addRect(innerRect, Direction.CW);
				innerPath.addRect(innerRect, Direction.CW);
			} 
		} else { 

6
CodeRank
This code example shows how to use the following methods:addRect, addRoundRect, reset
	// PRIVATE ==================================================================================== 
	 
	private void updateGeometry() { 
		final Rect b = getBounds();
		 
		mStrokePath.reset();
		mFillPath.reset();
		mIndicatorFillPath.reset();
		mIndicatorStrokePath.reset();
		 
		if (b.isEmpty()) {
			return; 
		} 
		 
		final boolean isHorizontal = mIndicatorDirection == IndicatorDirection.TOP
				|| mIndicatorDirection == IndicatorDirection.BOTTOM;
		final int innerCornerWidth = mCornerRadius - mStrokeWidth;
		final float sW = mStrokeWidth;
		final float iW = mIndicatorWidth;
		final float cR = mCornerRadius;

6
CodeRank
This code example shows how to use the following methods:addArc, addCircle, addOval, addRect, addRoundRect
        } 
    } 
 
    private void drawPath(Canvas canvas) {
 
        Path path = new Path();
 
        // 弧を追加 
        RectF oval = new RectF(10, 10, 60, 60);
        path.addArc(oval, 180, 90);
 
        // 円を追加 
        path.addCircle(95, 35, 25, Path.Direction.CW);
 
        // 楕円を追加 
        RectF oval2 = new RectF(130, 10, 230, 60);
        path.addOval(oval2, Path.Direction.CW);
 
        // 四角形を追加 
        RectF rect = new RectF(10, 70, 60, 120);

6
CodeRank
This code example shows how to use the following methods:addRoundRect, reset
                break; 
 
            case RECTANGLE:
            default: 
                if (mRadiiArray != null) {
                    mPath.reset();
                    mPath.addRoundRect(mRect, mRadiiArray, Path.Direction.CW);
                    canvas.drawPath(mPath, mFillPaint);
                } else { 
                    float rad = mRadius;
                    float r = Math.min(width, height) * 0.5f;
                    if (rad > r) {
                        rad = r;
                    } 
                    canvas.drawRoundRect(mRect, rad, rad, mFillPaint);
                } 
                break; 
        } 
 
        canvas.drawBitmap(bitmap, 0, 0, mMaskPaint);
6
CodeRank
This code example shows how to use the following methods:addRoundRect, lineTo, moveTo, reset
6
CodeRank
This code example shows how to use the following methods:addRoundRect, lineTo, moveTo
    } 
 
    @Override 
    public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
        Canvas canvas = new Canvas(bitmap);
        Path border = new Path();
        border.moveTo(0, 0);
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        float bs = mBorderSize / 100.0f * bitmap.getWidth();
        float r = mBorderCornerRadius / 100.0f * bitmap.getWidth();
        border.lineTo(0, h);
        border.lineTo(w, h);
        border.lineTo(w, 0);
        border.lineTo(0, 0);
        border.addRoundRect(new RectF(bs, bs, w - bs, h - bs),
                r, r, Path.Direction.CW);
 
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(mBorderColor);
6
CodeRank
This code example shows how to use the following methods:addRoundRect
    } 
    
    @Override 
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mClip = new Path();
        RectF rect = new RectF(0, 0, w, h);
        mClip.addRoundRect(rect, RADIUS, RADIUS, Direction.CW);
    } 
  
    @Override 
    protected void dispatchDraw(Canvas canvas) {
        canvas.save();
        canvas.clipPath(mClip);
        super.dispatchDraw(canvas);
        canvas.restore();
    }  
} 
5
CodeRank

Related Path addRoundRect Questions & Answers:

addRoundRect Method Overview
Add a closed round-rectangle contour to the path.
See Code Examples for other Android Path Methods: