在我的应用程序中,我正在使用 TwainDotNet 库,并且正在从平板扫描特定区域。
public Prasymas scanForm(Prasymas prasymas, bool isItFirstScan)
{
Enabled = false;
_settings = new ScanSettings();
_settings.UseDocumentFeeder = false;
_settings.ShowTwainUI = false;
_settings.ShowProgressIndicatorUI = true;
_settings.UseDuplex = false;
_settings.Resolution =
false
? ResolutionSettings.Fax : ResolutionSettings.ColourPhotocopier;
_settings.Page = PageSettings.Default;
if (!isItFirstScan)
{
_prasymas = prasymas;
AreaSettings = new AreaSettings(Units.Centimeters, 0.0f, 0.0f, (float)(_prasymas.maxScanAukstis), 0.0f);
}
else
{
_settings.Area = !false ? null : AreaSettings;
}
_settings.ShouldTransferAllPages = true;
_settings.Rotation = new RotationSettings()
{
AutomaticRotate = false,
AutomaticBorderDetection = false
};
try
{
_twain.SelectSource();
_twain.StartScanning(_settings);
}
catch (TwainException ex)
{
if (ex.Message == "Error opening data source")
{
_twain.SelectSource();
scanForm(_prasymas, isItFirstScan);
Enabled = true;
}
else
throw ex;
}
catch (Exception exc)
{
if (exc.Message == "Pasiuto skeneris")
{
scanForm(_prasymas, true);
}
else
throw exc;
}
Enabled = true;
return prasymas;
}
但结果当扫描开始并且扫描源是 Twain 驱动程序时,它会扫描整页,但如果我选择 WIA 驱动程序,我会得到专门选择的区域。主要思想是应用程序在第一次扫描整页时启动,下次它只扫描页面的特定高度。