简体   繁体   中英

twain scanner not acquiring the image from scanner

i implemented one applet to acquire the image from scanner for that i have used twain implementation.it is working fine while i am running the application as java applet but the problem is it is not able to acquire the image from scan device while i run from one html file .it is not giving any error and i am not able to debug the application. can any body tell me how can i resolve the issue.

this is my html

<html>
<head><title>Scann</title></head>
<body>
<center>
    <applet id="TwainApplet"
            code = "com.nic.applet.TwainExample.class"
            archive="TwainApplet.jar"
            width="200"
            height="60">
    </applet>
</center>
</body>
</html>

below is my Twain class..

public class TwainExample extends Applet implements ScannerListener{

  static TwainExample app; 

  Scanner scanner;

  public TwainExample(String[] argv)throws ScannerIOException{
    scanner=Scanner.getDevice();
    scanner.addListener(this);   
    scanner.acquire();
  }

  public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata){
    if(type.equals(ScannerIOMetadata.ACQUIRED)){
      BufferedImage image=metadata.getImage();
      System.out.println("Have an image now!");
      try{
        ImageIO.write(image, "png", new File("mmsc_image.png"));
      }catch(Exception e){
        e.printStackTrace();
      }
    }else if(type.equals(ScannerIOMetadata.NEGOTIATE)){
      ScannerDevice device=metadata.getDevice();
      try{
//        device.setShowUserInterface(true);
//        device.setShowProgressBar(true);
//        device.setResolution(100);
      }catch(Exception e){
        e.printStackTrace();
      }
    }else if(type.equals(ScannerIOMetadata.STATECHANGE)){
      System.err.println(metadata.getStateStr());
      if(metadata.isFinished()){
        System.exit(0);
      }
    }else if(type.equals(ScannerIOMetadata.EXCEPTION)){
      metadata.getException().printStackTrace();
    }
  }

  public static void main(String[] argv){
    try{
      app=new TwainExample(argv);
    }catch(Exception e){
      e.printStackTrace();
    }
 }
}

try this

public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata){
if(type.equals(ScannerIOMetadata.ACQUIRED)){
  BufferedImage image=metadata.getImage();
  System.out.println("Have an image now!");
  System.out.println("Have"+identy);
  try{

      File home = new File("C:\\Directory1");//المجلد الاساسي حق الموظفين
      File dir  = new File(home,identy);//مجلد الموظف عشان نحفظ فيه ملفات الموظف لوحده 
      if(!dir.exists()){ dir = home;}//اذا مجلد الموظف غير موجود احفظ في المجلد الاساسي
      File file = new File(dir,"we.jpg");//file.delete();
      ImageIO.write(image, "JPG", file);
//        ImageIO.write(image, "png", new File("C:\\Directory1//we.png"));
         System.out.println(file.getCanonicalPath());
         convertTOpdf();
      }catch(Exception e){
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, e.getMessage());
      }
    }else if(type.equals(ScannerIOMetadata.NEGOTIATE)){
      ScannerDevice device=metadata.getDevice();
      try{
        device.setShowUserInterface(true);
        device.setShowProgressBar(true);
        device.setResolution(100);
      }catch(Exception e){
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, e.getMessage());
      }
    }else if(type.equals(ScannerIOMetadata.STATECHANGE)){
      System.err.println(metadata.getStateStr());
      if(metadata.isFinished()){
        //System.exit(0);
      }
    }else if(type.equals(ScannerIOMetadata.EXCEPTION)){
      metadata.getException().printStackTrace();
    }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM