//合并多张图片为一张图片 public String mergeImgFile(List<String> list ,String assignUser, String filePath) { int size = list.size(); int height = 0; if (size == 0) { height = 150 * 1; } else { height = 150 * size; } BufferedImage bi = new BufferedImage(300, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); long len = 0L; for (int i = 0; i < list.size(); i++) { String s = list.get(i); try { BufferedImage image = null; if (!new File(s).exists()) { //s= "modeFile\\1px.png"; System.out.println(Arrays.toString(b));打印完整数组 // byte [] bu = image2byte("modeFile\\1px.png"); byte[] bu = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 3, 0, 0, 0, 3, 8, 6, 0, 0, 0, 86, 40, -75, -65, 0, 0, 0, 1, 115, 82, 71, 66, 0, -82, -50, 28, -23, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, -79, -113, 11, -4, 97, 5, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -61, 0, 0, 14, -61, 1, -57, 111, -88, 100, 0, 0, 0, 16, 73, 68, 65, 84, 24, 87, 99, -8, -113, 4, 112, 113, -2, -1, 7, 0, -69, -121, 35, -35, -124, -73, -16, -20, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126}; filePath = "modeFile"; image = (BufferedImage) ImageIO.read(new ByteArrayInputStream(bu)); } else { image = (BufferedImage) ImageIO.read(new File(s)); } len += new File(s).length(); g.drawImage(image, 0, i * 150, 300, 150, null); Font f = new Font("宋体", Font.PLAIN,68); Color mycolor = Color.black;//new Color(0, 0, 255); g.setColor(mycolor); g.setFont(f); g.drawString(assignUser,30,80); } catch (IOException e) { e.printStackTrace(); } } g.dispose(); Random random = new Random(); String fourRandom = random.nextInt(10000) + ""; int randLength = fourRandom.length(); if (randLength < 4) { for (int i = 1; i <= 4 - randLength; i++) { fourRandom = "0" + fourRandom; } } String fn = "test" + fourRandom + ".png"; String newImage = filePath + "\\" + fn; if (newImage != null && bi != null) { try { File outputfile = new File(newImage); ImageIO.write(bi, "png", outputfile); } catch (IOException e) { System.out.println(e.getMessage()); } } while (new File(newImage).length() >= len) { return newImage; } return ""; }
合并多张图片为一张图片并添加水印
最新推荐文章于 2024-03-11 09:30:37 发布