refactor(webcam): 优化摄像头控制逻辑
- 新增 setWebcam 方法,支持通过 ID 设置摄像头 - 修改 Operational 类中的摄像头相关操作,增加对新方法的支持 - 优化 WebCamUtils 类,统一摄像头初始化逻辑 - 调整 Main 类中的应用锁定逻辑,指定锁定文件路径 - 移除 Main 类中未使用的 logLocking 方法
This commit is contained in:
parent
fa525732d1
commit
0efb720dfc
|
@ -13,13 +13,15 @@ import javax.swing.*;
|
|||
|
||||
import org.aohe.constant.Control;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Slf4j
|
||||
public class Main {
|
||||
|
||||
private static final String JAVA_IO_TMPDIR = System.getProperty("java.io.tmpdir");
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
AppLocker locker = AppLocker.create("aoheSaneServiceLock").build();
|
||||
AppLocker locker = AppLocker.create("aoheSaneServiceLock").setPath(Paths.get(JAVA_IO_TMPDIR)).build();
|
||||
UIManager.setLookAndFeel(new FlatDarculaLaf());
|
||||
try {
|
||||
locker.lock();
|
||||
|
@ -39,7 +41,5 @@ public class Main {
|
|||
TrayFrameUtf8.initSystemTrayUTF8();
|
||||
}
|
||||
|
||||
private void logLocking(String message) {
|
||||
log.info("{}", message);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,9 +16,6 @@ import java.util.*;
|
|||
@Slf4j
|
||||
public class Operational {
|
||||
|
||||
|
||||
private static TwainScanner scanner = null;
|
||||
|
||||
public static String selectOperational(String path) {
|
||||
JSONObject json = JSONObject.parse(path);
|
||||
|
||||
|
@ -60,7 +57,12 @@ public class Operational {
|
|||
r = R.ok(WebCamUtils.getWebcams());
|
||||
}else if ("002002".equals(function)){
|
||||
//设置webcam
|
||||
WebCamUtils.setWebcam(param.getString("name"));
|
||||
Integer id = param.getInteger("id");
|
||||
if(id != null){
|
||||
WebCamUtils.setWebcam(id);
|
||||
}else{
|
||||
WebCamUtils.setWebcam(param.getString("name"));
|
||||
}
|
||||
r = R.ok(WebCamUtils.getViewSizes());
|
||||
}else if("002003".equals(function)){
|
||||
//获取摄像头分辨率
|
||||
|
@ -126,7 +128,7 @@ public class Operational {
|
|||
* 选中某一获取到的扫描仪
|
||||
* @return R<boolean> -> success
|
||||
*/
|
||||
public static R setScanner(String name) throws TwainException, InterruptedException {
|
||||
public static R setScanner(String name) throws TwainException {
|
||||
if(name == null || name.isEmpty()){
|
||||
return R.fail("扫描仪名字为空");
|
||||
}
|
||||
|
@ -216,9 +218,8 @@ public class Operational {
|
|||
* @param name 扫描仪名称
|
||||
* @param systemUI 是否使用打印机自带UI
|
||||
* @return R
|
||||
* @throws TwainException default error
|
||||
*/
|
||||
public static R startScan(String name, boolean systemUI ) throws TwainException {
|
||||
public static R startScan(String name, boolean systemUI ) {
|
||||
Source source = new Source();
|
||||
source.setName(name);
|
||||
source.setSystemUI(systemUI);
|
||||
|
|
|
@ -61,6 +61,18 @@ public class WebCamUtils {
|
|||
webcam = initWebcam();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置摄像头
|
||||
* @param id
|
||||
*/
|
||||
public static void setWebcam(int id){
|
||||
if(webcam!=null && webcam.isOpen()){
|
||||
webcam.close();
|
||||
}
|
||||
webcam = Webcam.getWebcams().get(id);
|
||||
webcam = initWebcam();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取摄像头列表
|
||||
* @return
|
||||
|
|
Loading…
Reference in New Issue