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

How to set the resolution (DPI)?

Forums › TWAIN Classic › How to set the resolution (DPI)?

  • This topic has 10 replies, 5 voices, and was last updated 11 years, 2 months ago by mmotovsk.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • July 27, 2007 at 9:03 am #22184 Reply
    dabd
    Participant
    • Topics - 3
    • Replies - 3
    • Total Posts - 6

    Hi,

    I am using the following code with JTwain to try to set the DPI to 499 x 499 but the resulting scanned image has 96 x 96 DPI. How can I set the resolution?
    I am using a HP ScanJet G3010.

    Thanks.

    source.open();
    if (source.isUIEnabled()) {
    source.setUIEnabled(false);
    }
    source.setIndicators(false);
    source.setRegion(0,0,source.getCurrentPhyscialWidth(),source.getPhysicalHeight());

    source.setXResolution(499);
    source.setYResolution(499);
    source.setBitDepth(8);
    source.setPixelType(JTwainConstants.TWPT_GRAY);

    source.acquireImage();
    source.saveLastAcquiredImageIntoFile("c:\temp\scan.JPG");
    July 27, 2007 at 12:15 pm #23997 Reply
    TheCrow99
    Participant
    • Topics - 6
    • Replies - 54
    • Total Posts - 60

    are you sure the resolution is supported by the scanner?

    do a dat_capability msg_get for the resolution before you scan and make sure you really set the resolution or at lest check the answer from the source when you set the resolution to make sure your command was correctly executed.

    July 27, 2007 at 1:33 pm #23998 Reply
    dabd
    Participant
    • Topics - 3
    • Replies - 3
    • Total Posts - 6

    @TheCrow99 wrote:

    are you sure the resolution is supported by the scanner?

    I am not sure it supports 499 x 499 but I scanned an image with resolution 200 x 200 using the scanner alone and it works. When I try to scan the image using JTwain with 200x 200 dpi settings I get a 96 x 96 dpi image.

    @TheCrow99 wrote:

    do a dat_capability msg_get for the resolution before you scan and make sure you really set the resolution or at lest check the answer from the source when you set the resolution to make sure your command was correctly executed.

    Could you please post an example of code of how to use dat_capability and msg_get from Java?

    How do I check the answer from the source?

    Thanks.

    July 27, 2007 at 3:52 pm #23999 Reply
    gabe
    Participant
    • Topics - 9
    • Replies - 583
    • Total Posts - 592

    When you’re setting resolution you should check what the units (ICAP_UNITS) are set to first – 499 x 499 pixels isn’t quite the same as 499×499 cm. See the capability ordering whitepaper for information on the order to set capabilities – https://www.twain.org/docs/CapOrderForWeb.PDF

    You also may want to check the supported resolution(s) with a Get before trying the Set, some devices will round to the nearest supported and others with simply disregard your setting – recheck executeing the Get op for the resolution after you execute the set should assure you that you have successfully set the capability.

    When you set the resolution are you getting an rc=success from the triplet?

    .

    July 28, 2007 at 2:59 pm #24000 Reply
    dabd
    Participant
    • Topics - 3
    • Replies - 3
    • Total Posts - 6

    @gabe wrote:

    When you’re setting resolution you should check what the units (ICAP_UNITS) are set to first – 499 x 499 pixels isn’t quite the same as 499×499 cm. See the capability ordering whitepaper for information on the order to set capabilities – https://www.twain.org/docs/CapOrderForWeb.PDF

    You also may want to check the supported resolution(s) with a Get before trying the Set, some devices will round to the nearest supported and others with simply disregard your setting – recheck executeing the Get op for the resolution after you execute the set should assure you that you have successfully set the capability.

    When you set the resolution are you getting an rc=success from the triplet?

    .

    I am using JTwain (Java) so I don’t know what “rc” is. Is it from the .NET implementation? Here is the code I am executing and the output. I tried setting the units before the resolution but it still doesn’t work.

    Source source = SourceManager.instance().selectSourceByName("HP Scanjet G3010 TWAIN");
    source.open();

    if (source.isUIEnabled()) {
    source.setUIEnabled(false);
    }
    source.setIndicators(false);

    System.out.println("============= BEFORE SETTING =============");
    System.out.println("bit depth: " + source.getCurrentBitDepth());
    System.out.println("units: " + source.getCurrentUnits()[0]);
    System.out.println("pixel type: " + source.getCurrentPixelType());
    System.out.println("x res: " + source.getCurrentXResolution());
    System.out.println("y res: " + source.getCurrentYResolution());

    source.setMinimumExceptionEnabled(false);
    source.setRegion(0,0,source.getCurrentPhyscialWidth(),source.getPhysicalHeight());
    source.setUnits(JTwainConstants.TWUN_PIXELS);
    source.setPixelType(JTwainConstants.TWPT_GRAY);
    source.setXResolution(300.0);
    source.setYResolution(300.0);
    source.setBitDepth(8);

    System.out.println("n" + "============= AFTER SETTING =============");
    System.out.println("bit depth: " + source.getCurrentBitDepth());
    System.out.println("units: " + source.getCurrentUnits()[0]);
    System.out.println("pixel type: " + source.getCurrentPixelType());
    System.out.println("x res: " + source.getCurrentXResolution());
    System.out.println("y res: " + source.getCurrentYResolution());

    source.acquireImage();
    source.saveLastAcquiredImageIntoFile("c:\temp\scan.JPG");

    ============= BEFORE SETTING =============
    bit depth: 8
    units: 0
    pixel type: 2
    x res: 200.0
    y res: 200.0

    ============= AFTER SETTING =============
    bit depth: 8
    units: 5
    pixel type: 1
    x res: 1.0
    y res: 1.0

    It looks like the scanner ignores the values and sets x res and y res to 1.0??!!
    But the scanned image file properties show that it has 96 dpi.

    July 28, 2007 at 3:22 pm #24001 Reply
    gabe
    Participant
    • Topics - 9
    • Replies - 583
    • Total Posts - 592

    rc is return code and it is from the twain spec. If you don’t think that the java wrapper you’re using makes the rc available to you recheck the docs for the library, it could be that the library’s author decieded not to expose it but it seems unlikely to me. While you’re looking for information on an rc look for information on the cc, condition code for the calls to twain as there are situation when dealing with twain that you need to know why a call failed. From the code you submitted I’m most interested in the rc for:


    source.setXResolution(300.0);

    but it looks like you’re on the right track. You see that before you set the units they were inches (and 300 wouldn’t make much sense in most cases nor be supported in any that I’ve ever heard of) and now you’re getting pixels as the units and your 300 is much more likely. Now add another set and right after you set the units to pixels (and double check that the setting ‘sticks’) recheck for the supported x/y resolution. Just execute the Get for x/y resolution after you set the units. In most cases you should either get an enumeration of supported values or a range of acceptable values with a stepsize between each value in the range.

    .

    July 28, 2007 at 4:01 pm #24002 Reply
    dabd
    Participant
    • Topics - 3
    • Replies - 3
    • Total Posts - 6

    @gabe wrote:

    rc is return code and it is from the twain spec. If you don’t think that the java wrapper you’re using makes the rc available to you recheck the docs for the library, it could be that the library’s author decieded not to expose it but it seems unlikely to me. While you’re looking for information on an rc look for information on the cc, condition code for the calls to twain as there are situation when dealing with twain that you need to know why a call failed. From the code you submitted I’m most interested in the rc for:


    source.setXResolution(300.0);

    but it looks like you’re on the right track. You see that before you set the units they were inches (and 300 wouldn’t make much sense in most cases nor be supported in any that I’ve ever heard of) and now you’re getting pixels as the units and your 300 is much more likely. Now add another set and right after you set the units to pixels (and double check that the setting ‘sticks’) recheck for the supported x/y resolution. Just execute the Get for x/y resolution after you set the units. In most cases you should either get an enumeration of supported values or a range of acceptable values with a stepsize between each value in the range.

    .

    Right after I set the units the get x resolution shows only one value in the range: 1.0.
    One important bit of information is that JTwain is not free and I am using a trial edition which has expired (maybe this is the cause of my problems I’m not sure).

    Anyway I’d be interested in a free solution with the only requisite that I must be able to use it from a Java application. Can I use OpenTwain from Java?

    Thanks.

    July 28, 2007 at 4:14 pm #24003 Reply
    gabe
    Participant
    • Topics - 9
    • Replies - 583
    • Total Posts - 592

    you can use opentwain from java is you know how to use a .net library from java and I’d bet heavily on this issue having something to do with your library. On the plus side you know somewhat at least whats going on and why you’re getting 96dpi.

    November 17, 2008 at 5:16 am #24004 Reply
    Shyam
    Participant
    • Topics - 0
    • Replies - 1
    • Total Posts - 1

    I am using JTwain and facing the same problem that dabd is facing. I have verified that the resolution (200 x 200) in which I am trying to scan is supported by the scanner. In fact I also verified that when UI is enabled we can see that the driver (in my case HP Scanner dialogue) has actually received the DPI settings, though getCurrentXResolution and getCurrentYResolution are reporting 1.0, but when the scanned image is verified in MSPaint it reports 96 x 96 DPI and GIMP reports 72 x 72 DPI.

    The code snippet used is as below

          source.setUnits( JTwainConstants.TWUN_PIXELS );
    source.setXResolution( 200.00 );
    source.setYResolution( 200.00 );
    ImageIO.write( source.acquireImageAsBufferedImage(), "jpeg", bos );
    JpegBase64 = Base64.encode( bos.toByteArray() );
    source.close();

    Any help will be much appreciated.

    November 17, 2008 at 5:59 am #24005 Reply
    gabe
    Participant
    • Topics - 9
    • Replies - 583
    • Total Posts - 592

    Don’t trust mspaint or any other application to verify the image properties. The image properties shown by all applications once you have processed the image have very little to do with what you received from the twain driver, often they just reflect how you (or the wrapper you are using) saved the image. To verify the settings that were used to acquire your image use ImageInfo in state 6 or 7.

    I have verified that the resolution (200 x 200)….
    …XResolution and YResolution are reporting 1.0…

    Those numbers are not relevant until there is a unit attached. You must incorporate Units into your resolution setting&getting if you want consistent results.

    .

    February 12, 2010 at 7:04 pm #24006 Reply
    mmotovsk
    Participant
    • Topics - 3
    • Replies - 13
    • Total Posts - 16

    I am using the following code with JTwain to try to set the DPI to 499 x 499 but the resulting scanned image has 96 x 96 DPI. How can I set the resolution?

    Try the following code from Morena – Image Acquisition Framework for Java (http://www.gnome.sk):


    TwainSource source=TwainManager.selectSource(null);
    source.setVisible(false);
    source.setGrayScaleMode();
    source.setResolution(499);
    MorenaImage image=new MorenaImage(source);
    System.err.println("Size of acquired image is "+
    +image.getWidth()+" x "
    +image.getHeight()+" x "
    +image.getPixelSize());

    TwainManager.close();

    You can also run TwainAutomatedTest.java (test.bat, test.sh located at the examples directory of the distribution package). It will write all supported capabilities of your Twain driver to the twainAutomatedTest.txt file. You can see there for the interval of the supported resolutions.

    Martin Motovsky
    Member of Gnome’s technical support

  • Author
    Posts
Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: How to set the resolution (DPI)?
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

  • PDF/R For who and where?
  • Making searchable PDF with PDF/R
  • Backward compatibility with PDF/A and traditional PDF
  • could not open the twain source. Make sure there is a valid source for your sca
  • Changing TWAIN driver defaults
  • 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.