TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

problem acquiring two images in a row

Forums › TWAIN Classic › problem acquiring two images in a row

  • This topic has 0 replies, 1 voice, and was last updated 13 years, 2 months ago by dabd.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • November 14, 2007 at 6:11 pm #22241 Reply
    dabd
    Participant
    • Topics - 3
    • Replies - 3
    • Total Posts - 6

    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;
    }
    }
  • Author
    Posts
Viewing 1 post (of 1 total)
Reply To: problem acquiring two images in a row
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • EPSON V600 TWAIN and WIA on Windows 10
  • When and how to use WaitForEvents command ?
  • Problem enumerating list of installed scanners in windows server 2012
  • Failed to create TWAIN progress! Error code is 1260.
  • To get the list of scanners from javascript client side (browser)
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.