|
|
@@ -34,89 +34,94 @@ public class ParticipantServiceTest extends ApplicationTests {
|
|
|
|
|
|
@Test
|
|
|
public void test() throws IOException, WriterException {
|
|
|
- BufferedImage shareImg = ImageIO.read(this.getClass()
|
|
|
- .getResourceAsStream("/static/certificate/2021-187-28197.png"));
|
|
|
- BufferedImage result = new BufferedImage(2480, 1748, BufferedImage.TYPE_INT_RGB);
|
|
|
- Graphics2D g = result.createGraphics();
|
|
|
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
- g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
- g.setComposite(AlphaComposite.SrcOver);
|
|
|
- g.drawImage(shareImg, 0, 0, null);
|
|
|
-
|
|
|
- // 二维码
|
|
|
+ String[] array = {"盛颖帆", "杨墨涵", "潘瑾汐", "朱建玥", "金兴蕾", "雷普", "王锦曦", "高嘉涵", "常彧嘉", "宋佳怡"};
|
|
|
+
|
|
|
+ for (String str : array) {
|
|
|
+
|
|
|
+
|
|
|
+ BufferedImage shareImg = ImageIO.read(this.getClass()
|
|
|
+ .getResourceAsStream("/static/certificate/2021-124-28198.png"));
|
|
|
+ BufferedImage result = new BufferedImage(2480, 1748, BufferedImage.TYPE_INT_RGB);
|
|
|
+ Graphics2D g = result.createGraphics();
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ g.setComposite(AlphaComposite.SrcOver);
|
|
|
+ g.drawImage(shareImg, 0, 0, null);
|
|
|
+
|
|
|
+ // 二维码
|
|
|
// BufferedImage avatar = ImageIO.read(new URL("http://yskj.njlyw.cn:8081/files/image/2021-11-04-12-36-43bJEcdPkI.jpg"));
|
|
|
- Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
|
|
|
- hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
|
|
- hints.put(EncodeHintType.MARGIN, 1);
|
|
|
- BitMatrix bitMatrix = new MultiFormatWriter().encode("http://yskj.njlyw.cn:8081/h5/home?programmeId=18705", BarcodeFormat.QR_CODE, 1000, 1000, hints);
|
|
|
+ Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
|
|
|
+ hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
|
|
+ hints.put(EncodeHintType.MARGIN, 1);
|
|
|
+ BitMatrix bitMatrix = new MultiFormatWriter().encode("http://yskj.njlyw.cn:8081/h5/home?programmeId=19798", BarcodeFormat.QR_CODE, 1000, 1000, hints);
|
|
|
// BufferedImage image = new BufferedImage(240, 240, BufferedImage.TYPE_INT_RGB);
|
|
|
- BufferedImage code = MatrixToImageWriter.toBufferedImage(bitMatrix);
|
|
|
+ BufferedImage code = MatrixToImageWriter.toBufferedImage(bitMatrix);
|
|
|
// BufferedImage avatar = ImageIO.read(new File("/Users/qiufangchao/Desktop/17824.png"));
|
|
|
|
|
|
// int size = Math.min(avatar.getWidth(), avatar.getHeight());
|
|
|
// BufferedImage subImg = avatar
|
|
|
// .getSubimage((avatar.getWidth() - size) / 2, (avatar.getHeight() - size) / 2, size, size);
|
|
|
|
|
|
- BufferedImage avatarImg = new BufferedImage(249, 249, BufferedImage.TYPE_INT_ARGB);
|
|
|
- Graphics2D g2 = avatarImg.createGraphics();
|
|
|
- g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
- g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
- g2.setComposite(AlphaComposite.SrcOver);
|
|
|
- g2.setBackground(Color.GREEN);
|
|
|
+ BufferedImage avatarImg = new BufferedImage(249, 249, BufferedImage.TYPE_INT_ARGB);
|
|
|
+ Graphics2D g2 = avatarImg.createGraphics();
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ g2.setComposite(AlphaComposite.SrcOver);
|
|
|
+ g2.setBackground(Color.GREEN);
|
|
|
// g2.setClip(new Ellipse2D.Float(0, 0, 68 * 2, 76 * 2)); //椭圆
|
|
|
|
|
|
- g2.drawImage(code, 0, 0, 249, 249, null);
|
|
|
- g.drawImage(avatarImg, 1894, 248, 249, 249, null);
|
|
|
+ g2.drawImage(code, 0, 0, 249, 249, null);
|
|
|
+ g.drawImage(avatarImg, 1894, 248, 249, 249, null);
|
|
|
|
|
|
|
|
|
- // 文字
|
|
|
- g.setColor(new Color(48, 52, 82)); //根据图片的背景设置水印颜色
|
|
|
- // 编号
|
|
|
- String small = "18705";
|
|
|
- Font fontSmall = new Font("黑体", Font.PLAIN, 35);
|
|
|
- g.setFont(fontSmall);
|
|
|
- g.drawString(small, 2000, 544);
|
|
|
+ // 文字
|
|
|
+ g.setColor(new Color(48, 52, 82)); //根据图片的背景设置水印颜色
|
|
|
+ // 编号
|
|
|
+ String small = "19798";
|
|
|
+ Font fontSmall = new Font("黑体", Font.PLAIN, 35);
|
|
|
+ g.setFont(fontSmall);
|
|
|
+ g.drawString(small, 2000, 544);
|
|
|
|
|
|
- // 姓名
|
|
|
- Font font = new Font("黑体", Font.BOLD, 60);
|
|
|
- String content = "田雨歆";
|
|
|
- // 加水印
|
|
|
- g.setFont(font); //设置字体
|
|
|
- //设置水印的坐标
|
|
|
- g.drawString(content, 400, 601); //画出水印
|
|
|
+ // 姓名
|
|
|
+ Font font = new Font("黑体", Font.BOLD, 60);
|
|
|
+// String content = "张泽清";
|
|
|
+ // 加水印
|
|
|
+ g.setFont(font); //设置字体
|
|
|
+ //设置水印的坐标
|
|
|
+ g.drawString(str, 400, 601); //画出水印
|
|
|
|
|
|
- // 节目名称
|
|
|
- String content1 = "人物素描";
|
|
|
+ // 节目名称
|
|
|
+ String content1 = "我对月亮说句话";
|
|
|
|
|
|
- if (content1.length() < 8) {
|
|
|
+ if (content1.length() < 8) {
|
|
|
// String body1 = "多声部手风琴原创作品《最";
|
|
|
// String body2 = "美的风景》";
|
|
|
// Font title = new Font("黑体", Font.PLAIN, 40);
|
|
|
// g.setFont(title);
|
|
|
// g.drawString(body1, 1200, 795);
|
|
|
- g.drawString(content1, 1300, 834);
|
|
|
- } else {
|
|
|
- g.drawString(content1, 1180, 834);
|
|
|
+ g.drawString(content1, 1300, 834);
|
|
|
+ } else {
|
|
|
+ g.drawString(content1, 1180, 834);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ g.dispose();
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
|
|
+ Thumbnails.of(result)
|
|
|
+ .scale(1)
|
|
|
+ .outputQuality(.9f)
|
|
|
+ .outputFormat("jpg")
|
|
|
+ .toOutputStream(out);
|
|
|
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
|
+
|
|
|
+ File file = new File("/Users/qiufangchao/Desktop/bu/我对月亮说句话-" + str + ".jpg");
|
|
|
+ byte[] buffer = new byte[in.available()];
|
|
|
+ in.read(buffer);
|
|
|
+ OutputStream outStream = new FileOutputStream(file);
|
|
|
+ outStream.write(buffer);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- g.dispose();
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
|
|
- Thumbnails.of(result)
|
|
|
- .scale(1)
|
|
|
- .outputQuality(.9f)
|
|
|
- .outputFormat("jpg")
|
|
|
- .toOutputStream(out);
|
|
|
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
|
-
|
|
|
- File file = new File("/Users/qiufangchao/Desktop/美术-一等奖-18705.jpg");
|
|
|
- byte[] buffer = new byte[in.available()];
|
|
|
- in.read(buffer);
|
|
|
- OutputStream outStream = new FileOutputStream(file);
|
|
|
- outStream.write(buffer);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Test
|