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

BitDepth Set for B/W (C#)

Forums › TWAIN Classic › BitDepth Set for B/W (C#)

  • This topic has 3 replies, 2 voices, and was last updated 12 years, 6 months ago by kitchenam.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • July 31, 2008 at 3:05 pm #22371 Reply
    kitchenam
    Participant
    • Topics - 1
    • Replies - 2
    • Total Posts - 3

    I’m trying to scan an image with the lowest resolution and bit depth settings possible. I’m using an HP Scanjet 7650 and scanning the image to JPG. In code (C#), I set the resolution to 150 for x and y, pixel type to 1 for B/W, and bit depth to 1. All settings are stat=success. When I view the properties of the saved image I see that the image pixel dimensions are 150/150 (as set), but the bit depth is 24 rather than 1 (inflating the image size). Anyone have a thought as to what the issue may be?

    Here’s the code…


    ...
    // set pixel type to black and white
    TwCapability ptCap = new TwCapability(TwCap.IPixelType, (short)TwPT.BW, TwType.Int16);
    rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, ptCap);
    if( rc != TwRC.Success)
    {
    CloseSrc();
    return false;
    }

    // set pixel bit depth to 1 bit (b/w)
    TwCapability bdCap = new TwCapability(TwCap.BitDepth, (short)1, TwType.UInt16);
    rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, bdCap);
    if( rc != TwRC.Success)
    {
    CloseSrc();
    return false;
    }
    ...

    Thanks…

    -aaron

    July 31, 2008 at 10:03 pm #24595 Reply
    gabe
    Participant
    • Topics - 9
    • Replies - 583
    • Total Posts - 592

    I’d try setting those caps in reverse order, mostly because https://www.twain.org/docs/CapOrderForWeb.PDF says that ICAP_BITDEPTH comes before ICAP_XRESOLUTION & ICAP_YRESOLUTION

    Then I’d run the Get triplet after all of my Set triplets to check that the device accepted my Sets (it’s odd but it’s twain)

    Then I’d check the twImageInfo while the image was coming down.

    If none of that worked I’d test my code against a known device – like a Kodak i30 in simulation mode.

    Failing that… yeah I dunno, if none of that works post back.

    EDITED: and i’d test this in the twain toolkit to see if the toolkit reproduced my problem, because if the toolkit reproduces your problem it’s more likely a problem with the driver. And with HP devices I would look for the ‘commercial’ or ‘minimal’ driver on the Cd – it isn’t the default and it works better.

    .

    August 20, 2008 at 9:10 pm #24596 Reply
    kitchenam
    Participant
    • Topics - 1
    • Replies - 2
    • Total Posts - 3

    Thanks for the reply, gabe. The scanner was apparently getting set properly. The problem I had was that the image was being saved via a method that uses the gdiplus.dll (from the NETMaster twain project) which, apparently, saves the image in a 24 bpp format regardless of the scanner settings. I modified the software to import the image into a .NET Image object and conducted the save from the .NET environment without altering the image. Problem solved.

    Thanks again.

    -aaron

    August 22, 2008 at 1:34 pm #24597 Reply
    kitchenam
    Participant
    • Topics - 1
    • Replies - 2
    • Total Posts - 3

    I thought I’d post the working SaveDIBAs method code for reference if anyone else runs across this issue.


    public static bool SaveDIBAs( string fileName, IntPtr bminfo, IntPtr pixdat )
    {

    Guid clsid;
    if( ! GetCodecClsid( fileName, out clsid ) )
    {
    MessageBox.Show( "Unknown picture format for extension " + Path.GetExtension( fileName ), "Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information );

    return false;
    }

    IntPtr img = IntPtr.Zero;
    int st = GdipCreateBitmapFromGdiDib( bminfo, pixdat, ref img );
    if( (st != 0) || (img == IntPtr.Zero) )
    return false;

    // obtain managed bitmap image from gdiplus dll
    MethodInfo mi = typeof(Bitmap).GetMethod("FromGDIplus", BindingFlags.Static | BindingFlags.NonPublic);
    Bitmap bmp = (Bitmap)mi.Invoke(null, new object[] {img});

    bmp.Save(fileName);
    bmp.Dispose();

    // causing the image to be saved in a default 24 bpp inflated format
    //st = GdipSaveImageToFile( img, fileName, ref clsid, IntPtr.Zero );

    GdipDisposeImage( img );
    return st == 0;
    }

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Reply #24596 in BitDepth Set for B/W (C#)
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

  • Scanner starts transfer when console gets closed (CITRIX)
  • Kodak RFS 3600
  • Didn’t save enough file scan
  • EPSON V600 TWAIN and WIA on Windows 10
  • When and how to use WaitForEvents command ?
  • 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.