mirror of
https://github.com/soukoku/ntwain.git
synced 2026-01-02 12:27:11 +08:00
Example of setting file xfer in wpf.
This commit is contained in:
@@ -367,6 +367,66 @@ namespace NTwain
|
|||||||
|
|
||||||
#endregion
|
#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
|
#region dpi
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -79,17 +79,18 @@ namespace Tester.WPF
|
|||||||
};
|
};
|
||||||
twain.TransferReady += (s, te) =>
|
twain.TransferReady += (s, te) =>
|
||||||
{
|
{
|
||||||
//var type = twain.GetCurrentCap<PixelType>(CapabilityId.ICapPixelType);
|
if (twain.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech) == XferMech.File)
|
||||||
//if (type == PixelType.BlackWhite)
|
{
|
||||||
//{
|
var formats = twain.CapGetImageFileFormat();
|
||||||
// te.ImageFormat = ImageFileFormat.Tiff;
|
var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;
|
||||||
// te.ImageCompression = Compression.Group31D;
|
|
||||||
// te.OutputFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.tif");
|
var fileSetup = new TWSetupFileXfer
|
||||||
//}
|
{
|
||||||
//else
|
Format = wantFormat,
|
||||||
//{
|
FileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.tif")
|
||||||
//te.OutputFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.bmp");
|
};
|
||||||
//}
|
var rc = twain.DGControl.SetupFileXfer.Set(fileSetup);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +134,11 @@ namespace Tester.WPF
|
|||||||
twain.CapSetPixelType(PixelType.BlackWhite);
|
twain.CapSetPixelType(PixelType.BlackWhite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (twain.CapGetImageXferMechs().Contains(XferMech.File))
|
||||||
|
{
|
||||||
|
twain.CapSetImageXferMech(XferMech.File);
|
||||||
|
}
|
||||||
|
|
||||||
step = "Enable DS";
|
step = "Enable DS";
|
||||||
rc = twain.EnableSource(SourceEnableMode.NoUI, false, hand, SynchronizationContext.Current);
|
rc = twain.EnableSource(SourceEnableMode.NoUI, false, hand, SynchronizationContext.Current);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user