How to create round corner image using volley library android

后端 未结 7 2268
旧巷少年郎
旧巷少年郎 2020-12-10 07:11

I am getting image urls from server with square shape I have to make it to rounded corner images.Actually I am using volley library ,I know how to create round corner images

7条回答
  •  青春惊慌失措
    2020-12-10 07:32

    This is how I did it:

    • In the volley library, copy the class called "NetworkImageView" and name it "NetworkImageViewCircle".

      private void setAnimateImageBitmap(final Bitmap bitmap, boolean fadeIn) {
      
      final Bitmap bmp;
      
      bmp = Bitmap.createBitmap(bitmap.getWidth(),
              bitmap.getHeight(), Bitmap.Config.ARGB_8888);
      BitmapShader shader = new BitmapShader(bitmap,
              BitmapShader.TileMode.CLAMP,
              BitmapShader.TileMode.CLAMP);
      
      float radius = Math.min(bitmap.getWidth(), bitmap.getHeight()) / 5;
      Canvas canvas = new Canvas(bmp);
      Paint paint = new Paint();
      paint.setAntiAlias(true);
      paint.setShader(shader);
      
      RectF rect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
      canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
      .
      .
      .
      

    This made the trick for me. hope it helps.

提交回复
热议问题