From a0edae2137fb26ada081c6027d60bd91723cae49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BB=BA=E5=9B=BD?= Date: Tue, 11 Feb 2025 15:46:52 +0800 Subject: [PATCH] =?UTF-8?q?build(twain-service):=20=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E8=87=B3=200.1.6.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 pom.xml 文件中将 twain-service 的版本号从 0.1.6 修改为 0.1.6.1 --- pom.xml | 2 +- src/main/java/org/aohe/show/IconUtil.java | 19 +++++++++++++++++ .../java/org/aohe/show/TrayFrameUtf8.java | 21 ++++++++----------- 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/aohe/show/IconUtil.java diff --git a/pom.xml b/pom.xml index 19f1c9c..9ae8f8b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.aohe twain-service - 0.1.6 + 0.1.6.1 8 diff --git a/src/main/java/org/aohe/show/IconUtil.java b/src/main/java/org/aohe/show/IconUtil.java new file mode 100644 index 0000000..932d065 --- /dev/null +++ b/src/main/java/org/aohe/show/IconUtil.java @@ -0,0 +1,19 @@ +package org.aohe.show; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ResourceUtil; +import lombok.extern.slf4j.Slf4j; + +import java.awt.*; + +@Slf4j +public class IconUtil { + public static Image getIcon() { + String iconPath = "ah.png"; + if(!FileUtil.exist("ah.png")){ + iconPath = ResourceUtil.getResource("ah.png").getFile(); + } + log.info("当前查找路径为:{}", FileUtil.getAbsolutePath(iconPath)); + return Toolkit.getDefaultToolkit().getImage(FileUtil.getAbsolutePath(iconPath)); + } +} diff --git a/src/main/java/org/aohe/show/TrayFrameUtf8.java b/src/main/java/org/aohe/show/TrayFrameUtf8.java index 6dbf00c..f6c3666 100644 --- a/src/main/java/org/aohe/show/TrayFrameUtf8.java +++ b/src/main/java/org/aohe/show/TrayFrameUtf8.java @@ -1,23 +1,14 @@ package org.aohe.show; -import cn.hutool.core.io.resource.ResourceUtil; -import cn.hutool.core.io.resource.UrlResource; -import com.github.sarxos.webcam.util.ImageUtils; import lombok.extern.slf4j.Slf4j; import org.aohe.constant.SocketEnum; import org.aohe.web.SocketUtils; -import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; import java.nio.charset.StandardCharsets; /** @@ -26,7 +17,7 @@ import java.nio.charset.StandardCharsets; @Slf4j public class TrayFrameUtf8 { - public static void initSystemTrayUTF8() throws IOException { + public static void initSystemTrayUTF8() throws InterruptedException { SocketUtils.start(SocketEnum.SCAN_SOCKET); //使用 JDialog 作为 JPopupMenu 载体 JDialog jDialog = new JDialog(); @@ -90,8 +81,13 @@ public class TrayFrameUtf8 { jPopupMenu.add(showMainFrame); jPopupMenu.add(exit); - URL url = ResourceUtil.getResource("ah.png"); - Image image = Toolkit.getDefaultToolkit().getImage(url.getFile()); + Image image = IconUtil.getIcon(); + + // 确保图片完全加载 + MediaTracker mediaTracker = new MediaTracker(new Component() {}); + mediaTracker.addImage(image, 0); + mediaTracker.waitForID(0); + // 创建系统托盘图标 TrayIcon trayIcon = new TrayIcon(image, "Scan Program For AH"); // 自动调整系统托盘图标大小 @@ -130,6 +126,7 @@ public class TrayFrameUtf8 { tray.add(trayIcon); } catch (AWTException ex) { ex.printStackTrace(); + log.error(ex.getMessage()); } }