How to set bitmap in circular imageview?

后端 未结 1 1677
故里飘歌
故里飘歌 2020-12-05 01:26

I have 1 circular imageview and I want to place bitmap inside the imageview. but when I set the compressed bitmap image it is always rectangle. Please help me to set bitmap

相关标签:
1条回答
  • 2020-12-05 02:08

    I am curious about how you created a circular ImageView. Can you share that secret ?? As far as creating a circular Bitmap is concerned, create a BitmapShader from the bitmap you want to show. Then create a ShapeDrawable (Oval) and assign the bitmap shader to it. Draw the drawable. Bam! circular image!

    Bitmap bitmap = getthebitmapyouwanttoshowinacirclefromsomewhere;
    Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    
    BitmapShader shader = new BitmapShader (bitmap,  TileMode.CLAMP, TileMode.CLAMP);
    Paint paint = new Paint();
            paint.setShader(shader);
    paint.setAntiAlias(true);
    Canvas c = new Canvas(circleBitmap);
    c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint);
    
    myImageView.setImageBitmap(circleBitmap);
    
    0 讨论(0)
提交回复
热议问题