Making an image circular with white circular border

后端 未结 10 2533
甜味超标
甜味超标 2021-02-19 19:32

How to make an image circular and give it white circular border? Is it necessary to use two image views – one for the image and other for the white border? Is there any other wa

10条回答
  •  难免孤独
    2021-02-19 20:09

    Here is a nice tutorial for it.

    in this tutorial they use a Method:-

    /* * Making image in circular shape */

    public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
      // TODO Auto-generated method stub
      int targetWidth = 50;
      int targetHeight = 50;
      Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, 
                                targetHeight,Bitmap.Config.ARGB_8888);
    
                    Canvas canvas = new Canvas(targetBitmap);
      Path path = new Path();
      path.addCircle(((float) targetWidth - 1) / 2,
      ((float) targetHeight - 1) / 2,
      (Math.min(((float) targetWidth), 
                    ((float) targetHeight)) / 2),
              Path.Direction.CCW);
    
                    canvas.clipPath(path);
      Bitmap sourceBitmap = scaleBitmapImage;
      canvas.drawBitmap(sourceBitmap, 
                                    new Rect(0, 0, sourceBitmap.getWidth(),
        sourceBitmap.getHeight()), 
                                    new Rect(0, 0, targetWidth,
        targetHeight), null);
      return targetBitmap;
     }
    

    For providing border around your imageView :

    Add this xml inside your drawable folder :

    =>rounded.xml

    
    
    
        
    
        
    
        
    
        
    
    
    

    Hope , this will helps

提交回复
热议问题