我想使用 morena api 和 twain 连接夏普网络扫描仪。如果扫描仪可以访问,一切都很好,但是当扫描仪无法访问时,jni 库会打开一个选择扫描仪窗口。我认为它是 twain ds 屏幕,我想禁用此屏幕。如果无法访问扫描仪,我想抛出错误而不是打开选择设备窗口。当我停止应用程序时,这个屏幕也会关闭,所以我认为它取决于 java 线程。问题是,如何在不停止整个程序的情况下停止此窗口的线程。我可以在另一个线程中运行 main 方法,并且可以找到该线程 id,但是当我停止该线程时,它不会关闭选择设备窗口。
import SK.gnome.morena.Morena;
import SK.gnome.morena.MorenaException;
import SK.gnome.morena.MorenaImage;
import SK.gnome.morena.MorenaSource;
import SK.gnome.twain.TwainManager;
import SK.gnome.twain.TwainSource;
import javax.swing.*;
public class HelloWorld
{ public static void main(String[] args) throws MorenaException
{
TwainSource[] list = null;
try {
list = TwainManager.listSources();
} catch (Exception var4) {
list = null;
}
MorenaSource source= list[1];
System.err.println("Selected source is "+source);
if (source!=null)
{ source.maskUnsupportedCapabilityException(false); // Lesson 3
source.maskBadValueException(false); // Lesson 3
source.setVisible(false); // Lesson 2
source.setColorMode(); // Lesson 2
source.setResolution(300); // Lesson 2
((TwainSource)source).setUnits(TwainSource.TWUN_CENTIMETERS);
source.setFrame(0, 0, 7.8, 10.5);
System.err.println("Image resolution is "+source.getResolution());
MorenaImage image=new MorenaImage(source);
System.err.println("Size of acquired image is "
+image.getWidth()+" x "
+image.getHeight()+" x "
+image.getPixelSize());
}
Morena.close();
}
}