如何设置位图中圆形的ImageView?圆形、图中、如何设置、ImageView

2023-09-12 07:20:59 作者:大声叫别控制

我有1个圆形的ImageView,我希望把位图ImageView的内部。 但是当我设置pssed COM $ P $位图图像总是矩形。 请帮我圆的ImageView设置位图。

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 in circular imageview.

感谢

推荐答案

我很好奇你是如何创建一个圆形ImageView的。您可以共享的秘密? 至于创造一个圆形的位图而言,创建你想显示位图BitmapShader。然后创建一个ShapeDrawable(椭圆形),并指定位图着色器吧。绘制绘制。巴姆!圆形图像!

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);
 
精彩推荐
图片推荐