Hello,
i need to add scanning to my app, so i was looking into some java libs to do it, but i don't have a scanner to try it....
can someone with one test this code, to see if it's worth the time to wrap it into a b4j lib
Also this jar in required in b4j additional libs folder
TIA
Nelson
i need to add scanning to my app, so i was looking into some java libs to do it, but i don't have a scanner to try it....
can someone with one test this code, to see if it's worth the time to wrap it into a b4j lib
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#AdditionalJar:uk.co.mmscomputing.device.twain.jar
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
Private NativeMe As JavaObject
NativeMe.InitializeNewInstance("b4j.example.main.TwainExample",Null)
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
#If Java
import java.io.File;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import uk.co.mmscomputing.device.scanner.Scanner;
import uk.co.mmscomputing.device.scanner.ScannerDevice;
import uk.co.mmscomputing.device.scanner.ScannerListener;
import uk.co.mmscomputing.device.scanner.ScannerIOException;
import uk.co.mmscomputing.device.scanner.ScannerIOMetadata;
public static class TwainExample implements ScannerListener{
//static TwainExample app;
Scanner scanner;
public TwainExample() 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();
}
}
}
#End If
Also this jar in required in b4j additional libs folder
TIA
Nelson