图片拼接 群组聊天头像设置(田字型 品字型)

因为公司项目需要,有一个群组聊天,头像显示是三个或者四个用户的头像的拼接,可能是品字型也可能是田字型。

自己想了一下,简单实现了一下,求大神们指教。谢谢

代码:

/** 横向连接两张图片 **/

public static Bitmap addHorizontalBitmap(Bitmap first, Bitmap second) {int width = first.getWidth() + second.getWidth();int height = Math.max(first.getHeight(), second.getHeight());Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);Paint paint = new Paint();paint.setColor(Color.WHITE);paint.setStrokeWidth(20);Canvas canvas = new Canvas(result);canvas.drawBitmap(first, 0, 0, null);canvas.drawLine(first.getWidth(), 0, first.getWidth(),first.getHeight(), paint);canvas.drawBitmap(second, first.getWidth(), 0, null);return result;}

/** 纵向连接两张图片 **/

public static Bitmap addVerticalBitmap(Bitmap first, Bitmap second) {int height = first.getHeight() + second.getHeight();int width = Math.max(first.getWidth(), second.getWidth());Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);Paint paint = new Paint();paint.setColor(Color.WHITE);Canvas canvas = new Canvas(result);canvas.drawBitmap(first, 0, 0, null);paint.setStrokeWidth(20);canvas.drawLine(0, first.getHeight(), first.getWidth(),first.getHeight(), paint);canvas.drawBitmap(second, 0, first.getHeight(), null);return result;}
/** 品字形拼接图片 第一张小 第二张大 **/
private Bitmap addTriangleBitmap(Bitmap first, Bitmap second) {int height = first.getHeight() + second.getHeight();int width = Math.max(first.getWidth(), second.getWidth());Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);Paint paint = new Paint();paint.setColor(Color.WHITE);Canvas canvas = new Canvas(result);canvas.drawBitmap(first, width / 2 - first.getWidth() / 2, 0, null);paint.setStrokeWidth(20);canvas.drawLine(width / 2 - first.getWidth() / 2, first.getHeight(),width / 2 + first.getWidth() / 2, first.getHeight(), paint);canvas.drawBitmap(second, 0, first.getHeight(), null);return result;}





本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部