如何设置位图中圆形的ImageView? [英] How to set bitmap in circular imageview?

查看:120
本文介绍了如何设置位图中圆形的ImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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);

这篇关于如何设置位图中圆形的ImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆