Home › Forums › TWAIN Classic › problem acquiring two images in a row
- This topic has 0 replies, 1 voice, and was last updated 16 years, 4 months ago by dabd.
- AuthorPosts
I am using morena to acquire two images from a single document.
The problem is that the second image is not acquired at all and the program crashes.This is the code that I use to acquire the first image. For the second image the code is exactly the same except the frame is set to different coordinates (so I can acquire a different part of the document).
I get the following error:
java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0
on the instruction awtImage.getWidth(null) because the morenaImage has 0 width and height.
I looked at all the methods for TwainSource to find a way to “reset” the source, because it looks like Morena didn’t finish the first job so it is unable to scan the second image, but I couldn’t find a suitable method.
Any tips please?
Thanks.
private static String acquireImg() throws Exception {
String result = null;
TwainSource tsource = getSource();
if (tsource != null) {
tsource.setVisible(false);
try {
tsource.setUnits(TwainConstants.TWUN_PIXELS);
tsource.setPixelType(TwainConstants.TWPT_GRAY);
if ("COLOR".equals(acquireType)) {
tsource.setColorMode();
} else {
tsource.setGrayScaleMode();
}
tsource.setBitDepth(8);
tsource.setResolution(499);
tsource.setFrame(400, 1000, 1400, 1300);
MorenaImage morenaImage = new MorenaImage(tsource);
Image awtImage = Toolkit.getDefaultToolkit().createImage( morenaImage);
BufferedImage image = new BufferedImage(awtImage.getWidth(null), awtImage.getHeight(null), BufferedImage.TYPE_BYTE_BINARY);
image.createGraphics().drawImage(awtImage, 0, 0, null);
result = Base64.encodeBytes(getJPG(image));
} catch (Exception e) {
e.printStackTrace();
}
return result;
} else {
return null;
}
}- AuthorPosts