服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

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


  javatwain may be a powerful solution,you can go to www.gnome.sk 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. <br>
  */
  
  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();
   }
  }

扫描关注微信公众号