简体   繁体   中英

NTwain ICapSupportedSizes is Not Supported

I'm using NTwain to scan documents into memory and I have it all working except for one part: When trying to set the size of the page to scan, it scans the entire width and height, rather than just the specified size.

I went and examined the details of NTwain's capabilities on the current source, and found the the ICapSupportedSizes was not supported for any action. 在此处输入图片说明

Here's how I'm setting the capabilities (this is on an open, valid source)

_twain.CurrentSource.Capabilities.ICapXResolution.SetValue(new TWFix32() { Whole = 600 });
_twain.CurrentSource.Capabilities.ICapYResolution.SetValue(new TWFix32() { Whole = 600 });
_twain.CurrentSource.Capabilities.ICapPixelType.SetValue(PixelType.BlackWhite);
_twain.CurrentSource.Capabilities.ICapSupportedSizes.SetValue(SupportedSize.USLegal);
_twain.CurrentSource.Capabilities.CapDuplexEnabled.SetValue(BoolType.False);

UPDATE :

I've found out that none of the settings are actually working. I set it as black and white, even if it shows black and white in the settings, it displays in color. Doesn't matter what DPI I set it at either as it defaults to 300 no matter what. I've updated it to grab out the source and use that to change the settings and call Enable, but it still doesn't work.

Any help is appreciated.

Thanks!

Enviornment Information

  • .NET Framework 4.6.1
  • Win Forms
  • C#
  • NTwain
  • Scanner: Canon Flatbed Scanner Unit 102

You will need to use the DGImage.ImageLayout property to set the page size in a generally-supported way.

For example:

var ds = _twain.CurrentSource;
ds.Capabilities.ICapUnits.SetValue(Unit.Inches);
ds.DGImage.ImageLayout.Get(out TWImageLayout imageLayout);
imageLayout.Frame = new TWFrame
{
    Left = 0,
    Right = pageWidthInInches,
    Top = 0,
    Bottom = pageHeightInInches
};
ds.DGImage.ImageLayout.Set(imageLayout);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM