android开发之 - 圆形头像
生活随笔
收集整理的這篇文章主要介紹了
android开发之 - 圆形头像
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
//最新第三方圓形頭像:
?
https://github.com/hdodenhof/CircleImageView?
?
https://github.com/MostafaGazar/CustomShapeImageView ??
?
?
?
?一段代碼,可以設置圓形頭像.
? ? 返回一個Bitmap對象.
?
? ==> 該列子是從網絡上獲取一張圖片。然后展示在ImageView的。
1:首先要確保網絡權限
<!-- 訪問網絡權限 --><uses-permission android:name="android.permission.INTERNET" />?
?
以下是關鍵代碼:
?
?
private InputStream inputStream;
Bitmap output;
?
?
圓形頭像代碼:
1
/* 圓形頭像 2 * 3 * @param bitmap 4 * @param ratio 5 * 按照截取比例來獲取圓形圖片 6 * @return 7 */ 8 public Bitmap getRoundedCornerBitmap(Bitmap bitmap) { 9 if (bitmap == null) { 10 bitmap = BitmapFactory.decodeStream(inputStream); 11 } 12 Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), 13 bitmap.getHeight(), Config.ARGB_8888);//Bitmap.Config.ARGB_4444比Bitmap.Config.ARGB_8888更省內存 14 Canvas canvas = new Canvas(outBitmap); 15 final int color = 0xff424242; 16 final Paint paint = new Paint(); 17 final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); 18 final RectF rectF = new RectF(rect); 19 final float roundPX = bitmap.getWidth() / 2 < bitmap.getHeight() / 2 ? bitmap 20 .getWidth() : bitmap.getHeight(); 21 paint.setAntiAlias(true); 22 canvas.drawARGB(0, 0, 0, 0); 23 paint.setColor(color); 24 canvas.drawRoundRect(rectF, roundPX, roundPX, paint); 25 paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); 26 canvas.drawBitmap(bitmap, rect, rect, paint); 27 return outBitmap; 28 } 29
?
?
? 額.復制粘貼試試吧.
轉載于:https://www.cnblogs.com/SomnusLove/p/3867417.html
總結
以上是生活随笔為你收集整理的android开发之 - 圆形头像的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CentOs6.5下独立安装Nginx篇
- 下一篇: C1 FlexGrid 行Style设置