Border over a bitmap with rounded corners in Android

前端 未结 6 1178
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 11:08

I used the below to make a bitmap with rounded corners. Now I want to draw a line around the bitmap.

private BitmapDrawable roundCornered(BitmapDrawable scal         


        
6条回答
  •  一整个雨季
    2020-12-01 11:42

    I use BitmapShader and drawRoundRect do it and it work for me, look at the screenshot

    enter image description here

    RectF roundRect; // the Rect you have to draw into
    Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    
    // draw the border at bottom
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(mBorderColor);
    canvas.drawRoundRect(roundRect, mRadius, mRadius, mPaint);
    
    // ------------------ draw scheme bitmap
    roundRect.set(itemRect.left + mBorderSize, itemRect.top + mBorderSize, itemRect.right - mBorderSize, itemRect.bottom - mBorderSize);
    Shader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mPaint.setShader(shader);
    canvas.drawRoundRect(roundRect, mRadius, mRadius, mPaint);
    mPaint.setShader(null);
    

提交回复
热议问题