生活随笔
收集整理的這篇文章主要介紹了
android 仿微信群聊头像 合成图片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
android 仿微信群聊頭像 合成圖片,微信中可以顯示出群頭像為多個用戶的頭像網格,這里講方法已經封裝好,
如果有記得點贊哦!!
先看效果:
使用例子:
@Override
public void onClick(View v
) {PNUtils
.runThread(new Runnable() {@Overridepublic void run() {Bitmap bitmap
= BitmapFactory
.decodeResource(getResources(), R
.mipmap
.cx_facebook_icon
);Bitmap bitmap1
= BitmapFactory
.decodeResource(getResources(), R
.mipmap
.cx_google_icon
);Bitmap bitmap3
= BitmapFactory
.decodeResource(getResources(), R
.mipmap
.cx_twitter
);Bitmap bitmap4
= BitmapFactory
.decodeResource(getResources(), R
.mipmap
.cx_weixin_icon
);List
<Bitmap> bitmaps
=new ArrayList<>();bitmaps
.add(bitmap
);bitmaps
.add(bitmap1
);bitmaps
.add(bitmap3
);bitmaps
.add(bitmap4
);final Bitmap bitmap2
=PNUtils
.createHeaderBitmap(bitmaps
, 300, 300, 2, "#000000");runOnUiThread(new Runnable() {@Overridepublic void run() {imageView
.setImageBitmap(bitmap2
);}});}});
}public static Bitmap
createHeaderBitmap(List
<Bitmap> bitmaps
,int maxWidth
,int maxHeight
, int columnNums
, String backgroundColor
) {if (bitmaps
.size()==0)return null
;int itemWidth
=maxWidth
/columnNums
;int itemHeight
=maxHeight
/columnNums
;int rows
=-1;Bitmap bitmap2
= Bitmap
.createBitmap(maxWidth
, maxHeight
, Bitmap
.Config
.ARGB_8888
);Canvas canvas
=new Canvas(bitmap2
);canvas
.drawColor(Color
.parseColor(backgroundColor
));for (int i
=0; i
<bitmaps
.size(); i
++) {int column
=i
%columnNums
;if (column
==0)rows
++;canvas
.drawBitmap(resizeBitmap(bitmaps
.get(i
), itemWidth
), column
*itemWidth
, rows
*itemHeight
, null
);}return bitmap2
;
}
public static Bitmap
resizeBitmap(Bitmap bitmap
, int newWidth
) {float scaleWidth
= ((float) newWidth
) / bitmap
.getWidth();Matrix matrix
= new Matrix();matrix
.postScale(scaleWidth
, scaleWidth
);Bitmap bmpScale
= Bitmap
.createBitmap(bitmap
, 0, 0, bitmap
.getWidth(), bitmap
.getHeight(), matrix
, true);return bmpScale
;
}
總結
以上是生活随笔為你收集整理的android 仿微信群聊头像 合成图片的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。