android 仿微信群聊头像 合成图片
16lz
2021-01-23
android 仿微信群聊头像 合成图片,微信中可以显示出群头像为多个用户的头像网格,这里讲方法已经封装好,
如果有记得点赞哦!!
热更新框架:https://github.com/jasonliyihang/speed_tools
网络优化工具集:https://github.com/woshiliyihang/pre-network
先看效果:
使用例子:
@Overridepublic void onClick(View v) { PNUtils.runThread(new Runnable() { @Override public 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() { @Override public 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;}
原文地址:http://pincha.shop/search/blogInfo/2932
更多相关文章
- Android中播放GIF图片动画
- 2010.12.15——— android listView 显示图片
- Android拍照、相册选取、裁剪图片综合Demo
- Android 图片对比(图片相似度)代码
- 麦子学院android开发笔记:Android更换RatingBar图片
- Android中关于Volley的使用(一)加载图片