feat(control): 增加双面扫描和系统UI选项

- 在 Operational 类中添加了双面扫描 (duple) 和系统UI (systemUI) 的支持
- 更新了 startScan 方法以支持系统UI选项
- 优化了 IconUtil 类中的图标加载逻辑
- 将项目版本号从 0.1.6.2 升级到 0.1.6.6
This commit is contained in:
李建国 2025-02-19 17:18:29 +08:00
parent 0bd6f83a44
commit 5cee6f61e9
3 changed files with 22 additions and 16 deletions

View File

@ -6,7 +6,7 @@
<groupId>org.aohe</groupId> <groupId>org.aohe</groupId>
<artifactId>twain-service</artifactId> <artifactId>twain-service</artifactId>
<version>0.1.6.2</version> <version>0.1.6.6</version>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>

View File

@ -16,6 +16,9 @@ import java.util.*;
@Slf4j @Slf4j
public class Operational { public class Operational {
//是否使用系统UI
private static Boolean isSystemUI = false;
public static String selectOperational(String path) { public static String selectOperational(String path) {
JSONObject json = JSONObject.parse(path); JSONObject json = JSONObject.parse(path);
@ -149,7 +152,6 @@ public class Operational {
TwainSource twainSource = openTwSource(); TwainSource twainSource = openTwSource();
TwainCapability[] capabilities = twainSource.getCapabilities(); TwainCapability[] capabilities = twainSource.getCapabilities();
Map<String, List<String>> map = new HashMap<>(); Map<String, List<String>> map = new HashMap<>();
for (TwainCapability cap : capabilities){ for (TwainCapability cap : capabilities){
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
@ -166,11 +168,6 @@ public class Operational {
}finally { }finally {
closeTwSource(); closeTwSource();
} }
} }
/** /**
@ -179,6 +176,7 @@ public class Operational {
* DPI --> double * DPI --> double
* 色彩模式 color 0,1,2 -> 黑白灰度彩色 * 色彩模式 color 0,1,2 -> 黑白灰度彩色
* 进纸模式 paper true,false -> 自动手动 * 进纸模式 paper true,false -> 自动手动
* 双面扫描 duple true,false -> 双面单面
* @param map 参数和值 * @param map 参数和值
* @return R * @return R
*/ */
@ -195,6 +193,13 @@ public class Operational {
if(map.get("paper") !=null){ if(map.get("paper") !=null){
twainSource.setCapability(Twain.CAP_FEEDERENABLED, map.getBooleanValue("paper")); twainSource.setCapability(Twain.CAP_FEEDERENABLED, map.getBooleanValue("paper"));
} }
if(map.get("duple") != null){
twainSource.setCapability(Twain.CAP_DUPLEXENABLED, map.getBooleanValue("duple"));
}
if(map.get("systemUI") != null){
isSystemUI = map.getBooleanValue("systemUI");
}
} catch (TwainException e) { } catch (TwainException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -209,7 +214,7 @@ public class Operational {
* @throws TwainException default error * @throws TwainException default error
*/ */
public static R startScan(String name) throws TwainException { public static R startScan(String name) throws TwainException {
return startScan(name, false); return startScan(name, isSystemUI);
} }
/** /**

View File

@ -1,7 +1,6 @@
package org.aohe.show; package org.aohe.show;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.io.resource.ResourceUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -10,18 +9,20 @@ import java.awt.*;
@Slf4j @Slf4j
public class IconUtil { public class IconUtil {
public static Image getIcon() { public static Image getIcon() {
ClassPathResource resource = new ClassPathResource("ah.png"); String iconPath = getProgramPathIcon();
if(FileUtil.exist(resource.getFile())){
return Toolkit.getDefaultToolkit().getImage(resource.getPath());
}
String iconPath = "..\\ah.png";
log.info("当前查找路径为外部:{}", FileUtil.getAbsolutePath(iconPath)); log.info("当前查找路径为外部:{}", FileUtil.getAbsolutePath(iconPath));
if(!FileUtil.exist("ah.png")){ if(!FileUtil.exist(iconPath)){
iconPath = ResourceUtil.getResource("ah.png").getFile(); iconPath = ResourceUtil.getResource("ah.png").getFile();
log.info("当前查找路径为内部:{}", FileUtil.getAbsolutePath(iconPath)); log.info("当前查找路径为内部:{}", FileUtil.getAbsolutePath(iconPath));
} }
log.info("当前程序图标最终路径路径为:{}", getProgramPathIcon());
return Toolkit.getDefaultToolkit().getImage(iconPath); return Toolkit.getDefaultToolkit().getImage(iconPath);
} }
public static String getProgramPathIcon(){
String resource = ResourceUtil.getResource("ah.png").getFile();
String absolutePath = FileUtil.getAbsolutePath(resource);
return absolutePath.replace("twain-service.exe!/", "");
}
} }