import javaawtBorderLayout;
import javaawtCursor;
import javaawtDimension;
import javaawtGraphics;
import javaawtRectangle;
import javaawtToolkit;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaawteventWindowAdapter;
import javaawteventWindowEvent;
import javaawteventWindowListener;
import javaawtimageBufferedImage;
import javaioFile;
import javaioFileInputStream;
import javaxswingJButton;
import javaxswingJComboBox;
import javaxswingJFrame;
import javaxswingJPanel;
import javaxswingJScrollPane;
import javaxswingJToolBar;
import javaxswingSwingUtilities;
import comsunimagecodecjpegJPEGCodec;
import comsunimagecodecjpegJPEGImageDecoder;
import eductgutwainJTwain;
/
这是显示扫描的frame
/
public class JTwacker extends JFrame {
class JPEGPanel extends JPanel {
/ Image for the inner class
/
protected BufferedImage mJPEGPanelBufferedImage;
/ Pnale to diaply the image
/
public JPEGPanel() {
// no op
}
/ Sets the bufferedimage into the class
@param bi BufferedImage
/
public void setBufferedImage(BufferedImage bi) {
if (bi == null) {
return;
}
mJPEGPanelBufferedImage = bi;
Dimension d = new Dimension(mJPEGPanelBufferedImagegetWidth(this),
mJPEGPanelBufferedImagegetHeight(this));
setPreferredSize(d);
revalidate();
repaint();
}
/ Paints the component
@param g Graphics object used for the painting
/
public void paintComponent(Graphics g) {
superpaintComponent(g);
Dimension d = getSize();
gsetColor(getBackground());
gfillRect(0, 0, dwidth, dheight);
if (mJPEGPanelBufferedImage != null) {
gdrawImage(mJPEGPanelBufferedImage, 0, 0, this);
}
}
}
protected JPEGPanel mJpegPanel;
protected BufferedImage mBufferedImage;
protected JComboBox mSourcesCombo;
protected JToolBar mToolBar;
/ Constructor
/
public JTwacker() {
super("测试");
mJpegPanel = new JPEGPanel();
JScrollPane ps = new JScrollPane(mJpegPanel,
JScrollPaneVERTICAL_SCROLLBAR_ALWAYS,
JScrollPaneHORIZONTAL_SCROLLBAR_ALWAYS);
getContentPane()add(ps, BorderLayoutCENTER);
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Systemexit(0);
}
};
addWindowListener(wndCloser);
mToolBar = new JToolBar("Twain");
mToolBarsetFloatable(false);
addButtons();
getContentPane()add(mToolBar, BorderLayoutNORTH);
setSize(800, 600);
/ Center the frame /
Dimension screenDim = ToolkitgetDefaultToolkit()getScreenSize();
Rectangle frameDim = getBounds();
setLocation(
(screenDimwidth - frameDimwidth) / 2,
(screenDimheight - frameDimheight) / 2
);
setVisible(true);
}
protected void addButtons(){
JButton _ab = new JButton("扫描");
_abaddActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
acquireImage();
}
});
mToolBaradd(_ab);
mToolBaraddSeparator();
if (eductgutwainJTwaingetInstance()isTwainAvailble()) {
String[] twainSources = JTwaingetInstance()getAvailableSources();
if (twainSources != null) {
mSourcesCombo = new JComboBox(twainSources);
} else {
mSourcesCombo = new JComboBox();
mSourcesComboaddItem("<NONE AVAILABLE>");
}
} else {
mSourcesCombo = new JComboBox();
mSourcesComboaddItem("<NONE AVAILABLE>");
}
mToolBaradd(mSourcesCombo);
}
protected void acquireImage() {
if (JTwaingetInstance()isTwainAvailble()){
if (mSourcesCombogetItemCount() > 0 ){
String _source = (String)mSourcesCombogetSelectedItem();
if (_source != null){
String _filename = JTwaingetInstance()acquire(_source);
Systemoutprintln(_filename);
if (_filename != null && _filenamelength() > 0) {
File fChoosen = new File(_filename);
// savetofile(fChoosen);
showImage(fChoosen);
} else {
Systemoutprintln("哎呀,怎么出错了!");
}
} // end if
} // end if
} // end if
}
protected void showImage(final File file) {
if (file == null || !fileexists()) {
return;
}
setCursor(CursorgetPredefinedCursor(CursorWAIT_CURSOR));
Thread runner = new Thread() {
public void run() {
try {
FileInputStream in = new FileInputStream(file);
JPEGImageDecoder decoder = JPEGCodeccreateJPEGDecoder(in);
mBufferedImage = decoderdecodeAsBufferedImage();
inclose();
SwingUtilitiesinvokeLater( new Runnable() {
public void run() {
reset();
}
});
}
catch (Exception ex) {
exprintStackTrace();
}
setCursor(CursorgetPredefinedCursor( CursorDEFAULT_CURSOR));
}
};
runnerstart();
}
//把扫描得到的保存为文件,然后上传到服务器或保存到数据库中
protected void savetofile(final File file) {
try {
File mfile=new File("c:\\ddjpg");
if (mfileexists()) {
mfiledelete();
}else {
filerenameTo(mfile);
}
} catch (Exception e) {
eprintStackTrace();
// TODO: handle exception
}
}
protected void reset() {
if (mBufferedImage != null) {
mJpegPanelsetBufferedImage(mBufferedImage);
}
}
public static void main(String argv[]) {
new JTwacker();
}
}
-------------------------
package eductgutwain;
/
这是调用动态链接库的类
/
public class JTwain {
private static final JTwain mInstance = new JTwain();
protected final String DLL_NAME = "jtwain";
private JTwain() {
initLib();
}
public static JTwain getInstance(){
return mInstance;
}
public native boolean isTwainAvailble();
public native String[] getAvailableSources();
public native String acquire();
public native String acquire(String sourceName);
private void initLib(){
try {
SystemloadLibrary(DLL_NAME);
}catch(Exception e) {
eprintStackTrace();
}
finally {
// Systemoutprintln("Loading : " + DLL_NAME + "dll");
}
}
}Microsoft Toolkit是一款免费的Windows8激活/win8激活工具和Office2010/2013激活工具,是由Office2010 Toolkit(Office2010激活工具)同一个作者制作。运行Microsoft Toolkit,点击界面右下角的Office图标进入Office Toolkit界面,点击Windows图标进入Windows Toolkit界面,对应激活Office2013和Windows8系统。
老版本则支持win7和office2010
1 选择Microsoft Toolkit并“以管理身份运行”。
2 点击Office或Windows产品定义KMS服务器后续的 *** 作步骤。
3 进入第二个选项卡“Activation”,并选择Tool *** 作方法“AutoKMS”
4 安装KMS服务,并在安装成功后点击“EZ-Activator”进行注册 *** 作。
5 安装成功后,显示结果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)