java

位置:IT落伍者 >> java >> 浏览文章

如何用 java 编写一个扫描仪程序


发布日期:2022年11月11日
 
如何用 java 编写一个扫描仪程序

javatwain may be a powerful solutionyou can go to wwwgnomesk to download the newest package

JavaTwain version is a part of the Morena Framework now

below is an simple example:

/*

* $Id: ExampleShowjavav // :: mmotovsk Exp $

*

* Copyright (c) Gnome spol s ro All Rights Reserved

*

* This software is the confidential and proprietary information of

* Gnome spol s ro You shall not disclose such Confidential

* Information and shall use it only in accordance with the terms

* of the license agreement you entered into with Gnome

*/

// JavaTwain package version

/**

ExampleShow demonstrates how to scan an image using defaults

from the Twain source <BR>

*/

import javaawt*;

import javaawtevent*;

import SKgnometwain*;

public class ExampleShow extends Frame

{ Image image;

public void paint(Graphics g)

{ if (null!=image)

gdrawImage(image this);

}

WindowListener windowAdapter=new WindowAdapter()

{ public void windowClosing(WindowEvent e)

{ Systemexit();

}

};

public ExampleShow()

{ try

{ addWindowListener(windowAdapter);

setTitle(ExampleShow Frame Application);

// Open TWAIN select source dialog box

// and initialize the source selected by the user

TwainSource source=TwainManagerselectSource(null);

image=ToolkitgetDefaultToolkit()createImage(source);

// wait for the image to be completed

MediaTracker tracker=new MediaTracker(this);

trackeraddImage(image );

// this is the moment the scanner user interface pops up

Systemerrprintln(Start loading image );

try

{ trackerwaitForAll();

}

catch (InterruptedException e)

{ Systemerrprintln(Image loading was interrupted!);

eprintStackTrace();

}

trackerremoveImage(image);

Systemerrprintln(Image loaded );

setSize(imagegetWidth(this) imagegetHeight(this));

setVisible(true);

TwainManagerclose();

}

catch (TwainException e)

{ eprintStackTrace();

}

}

public static void main(String[] args)

{ new ExampleShow();

}

}               

上一篇:Java技巧使用管道数据流传送数据

下一篇:几段实用小JAVA程序