0

当我在 spring mvc 中的 Web 应用程序中运行扫描仪时收到此错误。我使用了一个方法字节并将其作为字节数组返回。我认为这是错误

uk.co.mmscomputing.device.twain.TwainIOException: uk.co.mmscomputing.device.twain.TwainScanner.setException:
    uk.co.mmscomputing.device.twain.TwainSource.checkState:
    Source not in state 3 but in state 5.
    at uk.co.mmscomputing.device.twain.TwainScanner.signalException(TwainScanner.java:131)
    at uk.co.mmscomputing.device.twain.jtwain.signalException(jtwain.java:287)
    at uk.co.mmscomputing.device.twain.jtwain.cbexecute(jtwain.java:243)
    at uk.co.mmscomputing.device.twain.jtwain.nstart(Native Method)
    at uk.co.mmscomputing.device.twain.jtwain.access$200(jtwain.java:12)
    at uk.co.mmscomputing.device.twain.jtwain$1.run(jtwain.java:338)
uk.co.mmscomputing.device.twain.TwainIOException: uk.co.mmscomputing.device.twain.TwainSource.checkState:
    Source not in state 3 but in state 5.
    at uk.co.mmscomputing.device.twain.TwainSource.checkState(TwainSource.java:48)
    at uk.co.mmscomputing.device.twain.TwainSourceManager.openSource(TwainSourceManager.java:90)
    at uk.co.mmscomputing.device.twain.jtwain.cbexecute(jtwain.java:234)
    at uk.co.mmscomputing.device.twain.jtwain.nstart(Native Method)
    at uk.co.mmscomputing.device.twain.jtwain.access$200(jtwain.java:12)
    at uk.co.mmscomputing.device.twain.jtwain$1.run(jtwain.java:338)

我的代码是:

@RequestMapping( value = "/scanImage", method = RequestMethod.GET )
@ResponseBody
public byte[] scanImage()
{

    ByteArrayOutputStream byteArrayOutputStream = null;
    Scanner scanner = null;

    try
    {

        SCANIMAGE scanImage = new SCANIMAGE();
        scanImage.scanStarter();
        byte[] buffer = new byte[4096];
        byteArrayOutputStream = new ByteArrayOutputStream();
        FileInputStream inputStream = new FileInputStream( "D:/IMAGE.jpg" );
        System.out.println( "IMAGE Number : D:/IMAGE.jpg" );

        int read = 0;


        while ( ( read = inputStream.read( buffer ) ) != -1 )
        {
            byteArrayOutputStream.write( buffer, 0, read );

        }
    }
    catch ( ScannerIOException e )
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch ( FileNotFoundException e )
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch ( IOException e )
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return byteArrayOutputStream.toByteArray();
}
4

0 回答 0