android画一个圆形图片组件
生活随笔
收集整理的這篇文章主要介紹了
android画一个圆形图片组件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
imageview 顯示圓形圖片如下圖。
圓形頭像原理。
1、根據圖片創建一個大小相同的畫布。
2、在畫布上畫一個圓形。
3、畫一個繪制交集,顯示上層。
// 將圓形圖片,返回Bitmappublic static Bitmap getCircleBitmap(Bitmap bitmap) {int x = bitmap.getWidth();Bitmap output = Bitmap.createBitmap(x,x, Config.ARGB_8888);Canvas canvas = new Canvas(output);final int color = 0xff424242;final Paint paint = new Paint();// 根據原來圖片大小畫一個矩形final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());paint.setAntiAlias(true);paint.setColor(color);// 畫出一個圓canvas.drawCircle(x/2, x/2, x/2, paint);canvas.translate(-25, -6);// 取兩層繪制交集,顯示上層paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));// 將圖片畫上去canvas.drawBitmap(bitmap, rect, rect, paint);// 返回Bitmap對象return output;}使用。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" android:gravity="center"><org.open.CircleAvatarViewandroid:layout_width="38dp"android:layout_height="37dp"android:scaleType="centerCrop"android:src="@drawable/default_user_icon" ></org.open.CircleAvatarView> </LinearLayout>轉載于:https://www.cnblogs.com/loveyy/archive/2012/05/30/2526308.html
總結
以上是生活随笔為你收集整理的android画一个圆形图片组件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转:Android判断当前网络是否可用-
- 下一篇: SQl inner LOOP | HA