
1 /**
2 * 二维码流+背景图片流合成图片
3 * @param imagein2 二维码图片流
4 * @param backgroundPath 背景图片物流路径
5 * @param text 文本
6 * @return
7 */
8 public static InputStream changeMerchantSeatQrcodeImage(InputStream imagein2,String backgroundPath,String text){
9 InputStream imagein = null;
10 ImageOutputStream imOut = null;
11 try {
12 imagein = new FileInputStream(backgroundPath);
13 BufferedImage image = ImageIO.read(imagein);
14 BufferedImage image2 = ImageIO.read(imagein2);
15 Graphics g = image.getGraphics();
16 g.drawImage(image2, 285, 830,
17 image2.getWidth(), image2.getHeight(), null);
18 ByteArrayOutputStream bs = new ByteArrayOutputStream();
19 imOut = ImageIO.createImageOutputStream(bs);
20 ImageIO.write(image, "jpg", imOut);
21 InputStream is = new ByteArrayInputStream(bs.toByteArray());
22 return is;
23 } catch (Exception e) {
24 e.printStackTrace();
25 }finally {
26 try {
27 imagein.close();
28 imagein2.close();
29 imOut.close();
30 } catch (IOException e) {
31 e.printStackTrace();
32 }
33 }
34 return null;
35 }来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3598/viewspace-3138020/ ,如需转载,请注明出处,否则将追究法律责任。