From 4f3a98f19143865cdc1de4791e8a95d96bd40c65 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 01 八月 2025 13:27:59 +0800
Subject: [PATCH] yys 密码已重置

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/DateImageUtil.java |   61 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateImageUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateImageUtil.java
new file mode 100644
index 0000000..7fb91ee
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateImageUtil.java
@@ -0,0 +1,61 @@
+package com.ruoyi.common.utils;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.font.FontRenderContext;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+/**
+ * @Author zhuo
+ * @Date 2024/9/28
+ */
+public class DateImageUtil {
+
+    /**
+     * 鐢熸垚 褰撳墠鏃ユ湡鐨勭敾甯�
+     * @return
+     */
+    public static InputStream createDateImage(LocalDateTime date) {
+        int width = 80;
+        int height = 20;
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
+        if (date == null) {
+            date = LocalDateTime.now();
+        }
+        String s = date.format(formatter);
+
+        Font font = new Font("Serif", Font.BOLD, 10);
+        // 鍒涘缓涓�涓敾甯冿紙鑳屾櫙閫忔槑锛�
+        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+        // 鑾峰彇鐢诲竷鐨勭敾绗�
+        Graphics2D g2 = (Graphics2D) bi.getGraphics();
+        // 寮�濮嬬粯鍥�
+        g2.setComposite(AlphaComposite.Src); // 纭繚缁樺浘鏃舵槸閫忔槑鑳屾櫙
+        g2.setBackground(new Color(0, 0, 0, 0)); // 鑳屾櫙鑹蹭负閫忔槑
+        g2.clearRect(0, 0, width, height);
+        g2.setPaint(new Color(0, 0, 0)); // 璁剧疆缁樺埗棰滆壊
+        FontRenderContext context = g2.getFontRenderContext();
+        Rectangle2D bounds = font.getStringBounds(s, context);
+        double x = (width - bounds.getWidth()) / 2;
+        double y = (height - bounds.getHeight()) / 2;
+        double ascent = -bounds.getY();
+        double baseY = y + ascent;
+        g2.drawString(s, (int) x, (int) baseY);
+        g2.dispose(); // 閲婃斁鐢荤瑪璧勬簮
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+        try {
+            ImageIO.write(bi, "png", os);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return new ByteArrayInputStream(os.toByteArray());
+    }
+}

--
Gitblit v1.9.3