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());
}
}