「java连接扫描仪」java扫描器的用法

博主:adminadmin 2023-03-19 16:29:07 287

本篇文章给大家谈谈java连接扫描仪,以及java扫描器的用法对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

现在我在做JAVA连接扫描仪,问下有哪些扫描仪不支持TWAIN标准 请给出列表。那这些不支持的有什么解决办法

现在一般的扫描仪都带TWAIN或是ISIS的驱动,也有的是自身的驱动像中晶的,只要装上调用一下就行

用Java直接从扫描仪获得扫描数据,然后上载到服务器上,这样的程序需要利用那些知识点(有关Java)?

package edu.ctgu.JTwacker;

import java.awt.BorderLayout;

import java.awt.Cursor;

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.Rectangle;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileInputStream;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JToolBar;

import javax.swing.SwingUtilities;

import com.sun.image.codec.jpeg.JPEGCodec;

import com.sun.image.codec.jpeg.JPEGImageDecoder;

import edu.ctgu.twain.JTwain;

/*

这是显示扫描图片的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(mJPEGPanelBufferedImage.getWidth(this),

mJPEGPanelBufferedImage.getHeight(this));

setPreferredSize(d);

revalidate();

repaint();

}

/** Paints the component.

* @param g Graphics object used for the painting

*/

public void paintComponent(Graphics g) {

super.paintComponent(g);

Dimension d = getSize();

g.setColor(getBackground());

g.fillRect(0, 0, d.width, d.height);

if (mJPEGPanelBufferedImage != null) {

g.drawImage(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,

JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,

JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

getContentPane().add(ps, BorderLayout.CENTER);

WindowListener wndCloser = new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

};

addWindowListener(wndCloser);

mToolBar = new JToolBar("Twain");

mToolBar.setFloatable(false);

addButtons();

getContentPane().add(mToolBar, BorderLayout.NORTH);

setSize(800, 600);

/* Center the frame */

Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();

Rectangle frameDim = getBounds();

setLocation(

(screenDim.width - frameDim.width) / 2,

(screenDim.height - frameDim.height) / 2

);

setVisible(true);

}

protected void addButtons(){

JButton _ab = new JButton("扫描");

_ab.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

acquireImage();

}

});

mToolBar.add(_ab);

mToolBar.addSeparator();

if (edu.ctgu.twain.JTwain.getInstance().isTwainAvailble()) {

String[] twainSources = JTwain.getInstance().getAvailableSources();

if (twainSources != null) {

mSourcesCombo = new JComboBox(twainSources);

} else {

mSourcesCombo = new JComboBox();

mSourcesCombo.addItem("NONE AVAILABLE");

}

} else {

mSourcesCombo = new JComboBox();

mSourcesCombo.addItem("NONE AVAILABLE");

}

mToolBar.add(mSourcesCombo);

}

protected void acquireImage() {

if (JTwain.getInstance().isTwainAvailble()){

if (mSourcesCombo.getItemCount() 0 ){

String _source = (String)mSourcesCombo.getSelectedItem();

if (_source != null){

String _filename = JTwain.getInstance().acquire(_source);

System.out.println(_filename);

if (_filename != null _filename.length() 0) {

File fChoosen = new File(_filename);

// savetofile(fChoosen);

showImage(fChoosen);

} else {

System.out.println("哎呀,怎么出错了!");

}

} // end if

} // end if

} // end if

}

protected void showImage(final File file) {

if (file == null || !file.exists()) {

return;

}

setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

Thread runner = new Thread() {

public void run() {

try {

FileInputStream in = new FileInputStream(file);

JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);

mBufferedImage = decoder.decodeAsBufferedImage();

in.close();

SwingUtilities.invokeLater( new Runnable() {

public void run() {

reset();

}

});

}

catch (Exception ex) {

ex.printStackTrace();

}

setCursor(Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR));

}

};

runner.start();

}

//把扫描得到的图片保存为文件,然后上传到服务器或保存到数据库中

protected void savetofile(final File file) {

try {

File mfile=new File("c:\\dd.jpg");

if (mfile.exists()) {

mfile.delete();

}else {

file.renameTo(mfile);

}

} catch (Exception e) {

e.printStackTrace();

// TODO: handle exception

}

}

protected void reset() {

if (mBufferedImage != null) {

mJpegPanel.setBufferedImage(mBufferedImage);

}

}

public static void main(String argv[]) {

new JTwacker();

}

}

-------------------------

package edu.ctgu.twain;

/*

这是调用动态链接库的类

*/

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 {

System.loadLibrary(DLL_NAME);

}catch(Exception e) {

e.printStackTrace();

}

finally {

// System.out.println("Loading : " + DLL_NAME + ".dll");

}

}

}

用java程序来获取扫描仪里面的数据

下面是一个解决方案 , 用到 Morena 6.0 Framework 框架 里的 javaTwain功能 , 貌似搜了一下

好像要收费的,不过你可以找找是否有破解版的,没有的话,那就只有走偏门了 看是否能通过反编译 ,看改源代码了......

RE:

javatwain may be a powerful solution,you can go to to download the newest package.

JavaTwain version 5.1 is a part of the Morena 6.0 Framework now.

below is an simple example:

/*

* $Id: ExampleShow.java,v 1.5 2002/07/15 13:48:55 mmotovsk Exp $

*

* Copyright (c) 1999-2002 Gnome spol. s r.o. All Rights Reserved.

*

* This software is the confidential and proprietary information of

* Gnome spol. s r.o. 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 5.1

/**

ExampleShow demonstrates how to scan an image using defaults

from the Twain source.

*/

import java.awt.*;

import java.awt.event.*;

import SK.gnome.twain.*;

public class ExampleShow extends Frame

{ Image image;

public void paint(Graphics g)

{ if (null!=image)

g.drawImage(image, 0, 0, this);

}

WindowListener windowAdapter=new WindowAdapter()

{ public void windowClosing(WindowEvent e)

{ System.exit(0);

}

};

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=TwainManager.selectSource(null);

image=Toolkit.getDefaultToolkit().createImage(source);

// wait for the image to be completed

MediaTracker tracker=new MediaTracker(this);

tracker.addImage(image, 0);

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

System.err.println("Start loading image ...");

try

{ tracker.waitForAll();

}

catch (InterruptedException e)

{ System.err.println("Image loading was interrupted!");

e.printStackTrace();

}

tracker.removeImage(image);

System.err.println("Image loaded ...");

setSize(image.getWidth(this), image.getHeight(this));

setVisible(true);

TwainManager.close();

}

catch (TwainException e)

{ e.printStackTrace();

}

}

public static void main(String[] args)

{ new ExampleShow();

}

}

怎样用java调用扫描仪

首先要了解接口、再看是否标准的硬件驱动、或厂商是否提供驱动。。。。。。。。。如果没有JAVA的,就使用JNI调用

JAVA中的扫描仪

Scanner是jdk1.5新增的一个类,使用该类可创建一个对象,Scanner scan=new Scanner(System.in);意思是声明一个Scanner类的对象,并实例化,system.in即接收键盘输入。

JAVA怎么获取扫描仪器扫描的数据

每种OCR引擎提供了其各自的SDK,并且每种都有详细的API使用说明。我曾经使用过文通(DLL,在VB中Declare)、Fujitsu(提供OCX控件)、ReadIRIS(OCX,不过VB调用用问题,使用VC++重新封装OK)。 简单以FUjitsu为例:

1、工程中引用组件Fujistu TWIJOcr,将控制面板上出现的控件TWIJOcr添加到Form中

2、Form_load时初始化词典TWIJOcr1.CreateDictData

3、载入图像(可使用Kodak Imaging控件imgedit显示图像)

4、设置总页、图像对象,使用控件方法RecogText识别,保存输出结果等:

TWIJOcr1.TotalPage = 1

TWIJOcr1.ChangeCurrentPage 1, LoadPicture(inPict)

TWIJOcr1.RecogText

TWIJOcr1.SaveFileName = outText

TWIJOcr1.SaveFileType = 0

TWIJOcr1.SaveResult

关于java连接扫描仪和java扫描器的用法的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。