代码如下:

    /**
     * 画圆角
     * @param bitmap 要画圆角的bitmap
     * @param radiusPx  圆角大小,值越大越圆
     * @return    画完圆角的Bitmap
     */
    private Bitmap DrawRadius(Bitmap bitmap,float radiusPx){
        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();
        // 下面的四个参数分别为:left,top,right,bottom
        final Rect rect = new Rect(1, 0, bitmap.getWidth()-1, bitmap.getHeight()-1);          
        final RectF rectF = new RectF(rect);          
        final float roundPx = radiusPx;            
        paint.setAntiAlias(true);          
        canvas.drawARGB(0, 0, 0, 0);          
        paint.setColor(color);          
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);            
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));          
        canvas.drawBitmap(bitmap, rect, rect, paint);
        return output;
    }

Rect的四个参数前两个是以父窗口的左上角为参考点开始画,后两个可以分别理解为要画的宽度和高度。

 

相关文章:

  • 2021-06-24
  • 2021-09-13
  • 2022-12-23
  • 2021-05-15
  • 2021-08-26
  • 2022-02-25
  • 2022-12-23
猜你喜欢
  • 2021-11-06
  • 2021-05-26
  • 2021-04-25
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
相关资源
相似解决方案