java实现图片的合并与缩放

公司有一个需求是 将一个二维码放在 一个背景图当中。

因为二维码是从微信小程序官方获取的一个byte[],所以需要做一定的调整。

 

BufferedImage ground = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream(GROUND_PIC));
BufferedImage small = ImageIO.read(new ByteArrayInputStream(sourcePic));

首先从resource当中获取到背景图,并且获取到微信小程序的二维码(sourcePic)

Graphics2D g = ground.createGraphics();
g.drawImage(small, 214, 378, 220, 220, null);
g.dispose();

重绘ground。

ByteArrayOutputStream result = new ByteArrayOutputStream();
ImageIO.write(ground, "jpg", result);
result.flush();
byte[] resultByte = result.toByteArray();
result.close();

完成图片的处理。

 

posted on 2018-12-03 17:56  詹姆斯世界第一  阅读(540)  评论(0编辑  收藏  举报

导航