Border over a bitmap with rounded corners in Android

前端 未结 6 1176
隐瞒了意图╮
隐瞒了意图╮ 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:32

    I did many search to implement that effect by code, before I found another way but it's not perfect enough, you can see the jaggy on each corner, I set Paint.setAntiAlias(true), Paint.setDither(true), Paint.setFilterBitmap(true), but It doesn't work, so I hope somebody can help me. enter image description here

    RectF roundRect = new RectF(itemRect);
    
    Bitmap bitmap = scheme.getSchemeBitmap(getResources());
    
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(mSchemeSelectedColor);
    canvas.drawRoundRect(roundRect, mSchemeCornerRadius, mSchemeCornerRadius, mPaint);
    
    roundRect.set(itemRect.left + mBorderSize, itemRect.top + mBorderSize, itemRect.right - mBorderSize, itemRect.bottom - mBorderSize);
    Path clipPath = new Path();
    clipPath.addRoundRect(roundRect, mSchemeCornerRadius, mSchemeCornerRadius, Path.Direction.CW);
    canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipPath(clipPath);
    canvas.drawBitmap(bitmap, null, roundRect, mPaint);
    canvas.restore();
    

提交回复
热议问题