From 3647aa5008055528f075ee73002542a1399575ae Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期三, 19 三月 2025 14:45:39 +0800
Subject: [PATCH] 单点登录调整
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateImageUtil.java | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 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
index 7fb91ee..0ca66f5 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateImageUtil.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateImageUtil.java
@@ -9,6 +9,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -58,4 +59,41 @@
}
return new ByteArrayInputStream(os.toByteArray());
}
+
+ public static InputStream createDateImage(LocalDate date) {
+ int width = 80;
+ int height = 20;
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
+ if (date == null) {
+ date = LocalDate.now();
+ }
+ String s = date.format(formatter);
+
+ java.awt.Font font = new java.awt.Font("Serif", java.awt.Font.BOLD, 10);
+ // 鍒涘缓涓�涓敾甯冿紙鑳屾櫙閫忔槑锛�
+ BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ // 鑾峰彇鐢诲竷鐨勭敾绗�
+ Graphics2D g2 = (Graphics2D) bi.getGraphics();
+ // 寮�濮嬬粯鍥�
+ g2.setComposite(java.awt.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