Example of setting file xfer in wpf.

This commit is contained in:
soukoku 2014-04-07 19:46:03 -04:00
parent 2820cf7a8d
commit e915f6753b
2 changed files with 77 additions and 11 deletions

View File

@ -367,6 +367,66 @@ namespace NTwain
#endregion
#region xfer mech
/// <summary>
/// Gets the supported image <see cref="XferMech"/> for the current source.
/// Only call this at state 4 or higher.
/// </summary>
/// <param name="session">The session.</param>
/// <returns></returns>
public static IList<XferMech> CapGetImageXferMechs(this TwainSession session)
{
return session.GetCapabilityValues<XferMech>(CapabilityId.ICapXferMech, true);
}
/// <summary>
/// Gets the supported audio <see cref="XferMech"/> for the current source.
/// Only call this at state 4 or higher.
/// </summary>
/// <param name="session">The session.</param>
/// <returns></returns>
public static IList<XferMech> CapGetAudioXferMechs(this TwainSession session)
{
return session.GetCapabilityValues<XferMech>(CapabilityId.ACapXferMech, true);
}
/// <summary>
/// Change the image xfer type for the current source.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="type">The type.</param>
/// <returns></returns>
public static ReturnCode CapSetImageXferMech(this TwainSession session, XferMech type)
{
var one = new TWOneValue();
one.Item = (uint)type;
one.ItemType = ItemType.UInt16;
using (TWCapability dx = new TWCapability(CapabilityId.ICapXferMech, one))
{
return session.DGControl.Capability.Set(dx);
}
}
/// <summary>
/// Change the audio xfer type for the current source.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="type">The type.</param>
/// <returns></returns>
public static ReturnCode CapSetAudioXferMech(this TwainSession session, XferMech type)
{
var one = new TWOneValue();
one.Item = (uint)type;
one.ItemType = ItemType.UInt16;
using (TWCapability dx = new TWCapability(CapabilityId.ACapXferMech, one))
{
return session.DGControl.Capability.Set(dx);
}
}
#endregion
#region dpi
/// <summary>

View File

@ -79,17 +79,18 @@ namespace Tester.WPF
};
twain.TransferReady += (s, te) =>
{
//var type = twain.GetCurrentCap<PixelType>(CapabilityId.ICapPixelType);
//if (type == PixelType.BlackWhite)
//{
// te.ImageFormat = ImageFileFormat.Tiff;
// te.ImageCompression = Compression.Group31D;
// te.OutputFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.tif");
//}
//else
//{
//te.OutputFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.bmp");
//}
if (twain.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech) == XferMech.File)
{
var formats = twain.CapGetImageFileFormat();
var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;
var fileSetup = new TWSetupFileXfer
{
Format = wantFormat,
FileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.tif")
};
var rc = twain.DGControl.SetupFileXfer.Set(fileSetup);
}
};
}
@ -133,6 +134,11 @@ namespace Tester.WPF
twain.CapSetPixelType(PixelType.BlackWhite);
}
if (twain.CapGetImageXferMechs().Contains(XferMech.File))
{
twain.CapSetImageXferMech(XferMech.File);
}
step = "Enable DS";
rc = twain.EnableSource(SourceEnableMode.NoUI, false, hand, SynchronizationContext.Current);
return;