Border over a bitmap with rounded corners in Android

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

    my way:

     public static Bitmap getRoundedCornerBitmap1(Bitmap bitmap, int color, int cornerDips, int borderDips) {
    
    
                Bitmap output = Bitmap.createBitmap(bitmap.getWidth()+2*borderDips,
                        bitmap.getHeight()+2*borderDips,
                        Bitmap.Config.ARGB_8888);
    
                Canvas canvas = new Canvas(output);
    
                canvas.drawColor(Color.TRANSPARENT);
    
                final RectF rectF = new RectF(0, 0, output.getWidth(), output.getHeight());
                final Paint paint = new Paint();
                // prepare canvas for transfer
                paint.setAntiAlias(true);
                paint.setStrokeWidth((float) borderDips);
                paint.setColor(Color.WHITE);
                paint.setStyle(Paint.Style.FILL);
    
                canvas.drawRoundRect(rectF, borderDips, borderDips, paint);
    
                canvas.drawBitmap(bitmap, borderDips, borderDips, null);
                bitmap.recycle();
                return output;
            }
    

    Result

提交回复
热议问题