mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-04 20:24:42 +08:00
Add net5.0-windows build on x86 apps for now.
This commit is contained in:
parent
2e3f7422df
commit
06eb14545b
30
NTwain.sln
30
NTwain.sln
@ -24,6 +24,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Console", "samples\S
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B77C17FE-FD84-4FF4-9A1C-D49DB1749C9C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Net5Console", "samples\Sample.Net5Console\Sample.Net5Console.csproj", "{DDEA155C-68E9-4B42-8390-01B060DB25DB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Net5Winform", "samples\Sample.Net5Winform\Sample.Net5Winform.csproj", "{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -83,6 +87,30 @@ Global
|
||||
{12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|x86.Build.0 = Release|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -92,6 +120,8 @@ Global
|
||||
{4FC243F1-318E-4FA9-9EBD-2CA3A8F35425} = {2F906640-1664-4960-93D2-A054AC6E66A3}
|
||||
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D} = {2F906640-1664-4960-93D2-A054AC6E66A3}
|
||||
{12D761EF-68DF-41CE-92EF-0C7AE81857A3} = {2F906640-1664-4960-93D2-A054AC6E66A3}
|
||||
{DDEA155C-68E9-4B42-8390-01B060DB25DB} = {2F906640-1664-4960-93D2-A054AC6E66A3}
|
||||
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F} = {2F906640-1664-4960-93D2-A054AC6E66A3}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A823206C-F8D5-491B-8B01-B9A5884FAEA1}
|
||||
|
107
samples/Sample.Net5Console/Program.cs
Normal file
107
samples/Sample.Net5Console/Program.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
||||
namespace Sample.Net5Console
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (PlatformInfo.Current.IsApp64Bit)
|
||||
{
|
||||
Console.WriteLine("[64bit]");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("[32bit]");
|
||||
}
|
||||
// just an amusing example to do twain in console without UI
|
||||
ThreadPool.QueueUserWorkItem(o =>
|
||||
{
|
||||
try
|
||||
{
|
||||
DoTwainWork();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("ERROR: " + ex.ToString());
|
||||
}
|
||||
});
|
||||
Console.WriteLine("Test started, press Enter to exit.");
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static readonly TwainSession twain = InitTwain();
|
||||
private static TwainSession InitTwain()
|
||||
{
|
||||
var twain = new TwainSession(TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetExecutingAssembly()));
|
||||
twain.TransferReady += (s, e) =>
|
||||
{
|
||||
Console.WriteLine("Got xfer ready on thread {0}.", Thread.CurrentThread.ManagedThreadId);
|
||||
};
|
||||
twain.DataTransferred += (s, e) =>
|
||||
{
|
||||
if (e.NativeData != IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("SUCCESS! Got twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("BUMMER! No twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
|
||||
}
|
||||
};
|
||||
|
||||
twain.SourceDisabled += (s, e) =>
|
||||
{
|
||||
Console.WriteLine("Source disabled on thread {0}.", Thread.CurrentThread.ManagedThreadId);
|
||||
var rc = twain.CurrentSource.Close();
|
||||
rc = twain.Close();
|
||||
};
|
||||
return twain;
|
||||
}
|
||||
|
||||
const string SAMPLE_SOURCE = "TWAIN2 FreeImage Software Scanner";
|
||||
static void DoTwainWork()
|
||||
{
|
||||
Console.WriteLine("Getting ready to do twain stuff on thread {0}...", Thread.CurrentThread.ManagedThreadId);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
var rc = twain.Open();
|
||||
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
var hit = twain.FirstOrDefault(s => string.Equals(s.Name, SAMPLE_SOURCE));
|
||||
if (hit == null)
|
||||
{
|
||||
Console.WriteLine("The sample source \"" + SAMPLE_SOURCE + "\" is not installed.");
|
||||
twain.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = hit.Open();
|
||||
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
Console.WriteLine("Starting capture from the sample source...");
|
||||
rc = hit.Enable(SourceEnableMode.NoUI, false, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
twain.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Failed to open dsm with rc={0}!", rc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
13
samples/Sample.Net5Console/Sample.Net5Console.csproj
Normal file
13
samples/Sample.Net5Console/Sample.Net5Console.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
23
samples/Sample.Net5Winform/Program.cs
Normal file
23
samples/Sample.Net5Winform/Program.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Sample.Net5Winform
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new TestForm());
|
||||
}
|
||||
}
|
||||
}
|
15
samples/Sample.Net5Winform/Sample.Net5Winform.csproj
Normal file
15
samples/Sample.Net5Winform/Sample.Net5Winform.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ApplicationIcon>scanner.ico</ApplicationIcon>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
342
samples/Sample.Net5Winform/TestForm.Designer.cs
generated
Normal file
342
samples/Sample.Net5Winform/TestForm.Designer.cs
generated
Normal file
@ -0,0 +1,342 @@
|
||||
|
||||
namespace Sample.Net5Winform
|
||||
{
|
||||
partial class TestForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestForm));
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
|
||||
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
|
||||
this.btnSources = new System.Windows.Forms.ToolStripDropDownButton();
|
||||
this.sepSourceList = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.reloadSourcesListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.btnStartCapture = new System.Windows.Forms.ToolStripButton();
|
||||
this.btnStopScan = new System.Windows.Forms.ToolStripButton();
|
||||
this.btnSaveImage = new System.Windows.Forms.ToolStripButton();
|
||||
this.panelOptions = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.groupDuplex = new System.Windows.Forms.GroupBox();
|
||||
this.ckDuplex = new System.Windows.Forms.CheckBox();
|
||||
this.groupSize = new System.Windows.Forms.GroupBox();
|
||||
this.comboSize = new System.Windows.Forms.ComboBox();
|
||||
this.groupDepth = new System.Windows.Forms.GroupBox();
|
||||
this.comboDepth = new System.Windows.Forms.ComboBox();
|
||||
this.groupDPI = new System.Windows.Forms.GroupBox();
|
||||
this.comboDPI = new System.Windows.Forms.ComboBox();
|
||||
this.btnAllSettings = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.toolStrip1.SuspendLayout();
|
||||
this.panelOptions.SuspendLayout();
|
||||
this.groupDuplex.SuspendLayout();
|
||||
this.groupSize.SuspendLayout();
|
||||
this.groupDepth.SuspendLayout();
|
||||
this.groupDPI.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(259, 25);
|
||||
this.pictureBox1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(677, 500);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||
this.pictureBox1.TabIndex = 1;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// saveFileDialog1
|
||||
//
|
||||
this.saveFileDialog1.FileName = "Test";
|
||||
this.saveFileDialog1.Filter = "png files|*.png";
|
||||
this.saveFileDialog1.Title = "Save Image";
|
||||
//
|
||||
// toolStrip1
|
||||
//
|
||||
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.btnSources,
|
||||
this.btnStartCapture,
|
||||
this.btnStopScan,
|
||||
this.btnSaveImage});
|
||||
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.toolStrip1.Name = "toolStrip1";
|
||||
this.toolStrip1.Size = new System.Drawing.Size(936, 25);
|
||||
this.toolStrip1.TabIndex = 2;
|
||||
this.toolStrip1.Text = "toolStrip1";
|
||||
//
|
||||
// btnSources
|
||||
//
|
||||
this.btnSources.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
this.btnSources.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.sepSourceList,
|
||||
this.reloadSourcesListToolStripMenuItem});
|
||||
this.btnSources.Image = ((System.Drawing.Image)(resources.GetObject("btnSources.Image")));
|
||||
this.btnSources.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.btnSources.Name = "btnSources";
|
||||
this.btnSources.Size = new System.Drawing.Size(94, 22);
|
||||
this.btnSources.Text = "Select &sources";
|
||||
this.btnSources.DropDownOpening += new System.EventHandler(this.btnSources_DropDownOpening);
|
||||
//
|
||||
// sepSourceList
|
||||
//
|
||||
this.sepSourceList.Name = "sepSourceList";
|
||||
this.sepSourceList.Size = new System.Drawing.Size(168, 6);
|
||||
//
|
||||
// reloadSourcesListToolStripMenuItem
|
||||
//
|
||||
this.reloadSourcesListToolStripMenuItem.Name = "reloadSourcesListToolStripMenuItem";
|
||||
this.reloadSourcesListToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
|
||||
this.reloadSourcesListToolStripMenuItem.Text = "&Reload sources list";
|
||||
this.reloadSourcesListToolStripMenuItem.Click += new System.EventHandler(this.reloadSourcesListToolStripMenuItem_Click);
|
||||
//
|
||||
// btnStartCapture
|
||||
//
|
||||
this.btnStartCapture.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
this.btnStartCapture.Enabled = false;
|
||||
this.btnStartCapture.Image = ((System.Drawing.Image)(resources.GetObject("btnStartCapture.Image")));
|
||||
this.btnStartCapture.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.btnStartCapture.Name = "btnStartCapture";
|
||||
this.btnStartCapture.Size = new System.Drawing.Size(62, 22);
|
||||
this.btnStartCapture.Text = "S&tart scan";
|
||||
this.btnStartCapture.Click += new System.EventHandler(this.btnStartCapture_Click);
|
||||
//
|
||||
// btnStopScan
|
||||
//
|
||||
this.btnStopScan.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
this.btnStopScan.Enabled = false;
|
||||
this.btnStopScan.Image = ((System.Drawing.Image)(resources.GetObject("btnStopScan.Image")));
|
||||
this.btnStopScan.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.btnStopScan.Name = "btnStopScan";
|
||||
this.btnStopScan.Size = new System.Drawing.Size(62, 22);
|
||||
this.btnStopScan.Text = "Sto&p scan";
|
||||
this.btnStopScan.Click += new System.EventHandler(this.btnStopScan_Click);
|
||||
//
|
||||
// btnSaveImage
|
||||
//
|
||||
this.btnSaveImage.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
this.btnSaveImage.Image = ((System.Drawing.Image)(resources.GetObject("btnSaveImage.Image")));
|
||||
this.btnSaveImage.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.btnSaveImage.Name = "btnSaveImage";
|
||||
this.btnSaveImage.Size = new System.Drawing.Size(71, 22);
|
||||
this.btnSaveImage.Text = "S&ave image";
|
||||
this.btnSaveImage.Click += new System.EventHandler(this.btnSaveImage_Click);
|
||||
//
|
||||
// panelOptions
|
||||
//
|
||||
this.panelOptions.AutoScroll = true;
|
||||
this.panelOptions.ColumnCount = 1;
|
||||
this.panelOptions.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.panelOptions.Controls.Add(this.groupDuplex, 0, 3);
|
||||
this.panelOptions.Controls.Add(this.groupSize, 0, 2);
|
||||
this.panelOptions.Controls.Add(this.groupDepth, 0, 1);
|
||||
this.panelOptions.Controls.Add(this.groupDPI, 0, 0);
|
||||
this.panelOptions.Controls.Add(this.btnAllSettings, 0, 6);
|
||||
this.panelOptions.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.panelOptions.Location = new System.Drawing.Point(0, 25);
|
||||
this.panelOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.panelOptions.Name = "panelOptions";
|
||||
this.panelOptions.RowCount = 7;
|
||||
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
|
||||
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
|
||||
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
|
||||
this.panelOptions.Size = new System.Drawing.Size(259, 500);
|
||||
this.panelOptions.TabIndex = 3;
|
||||
//
|
||||
// groupDuplex
|
||||
//
|
||||
this.groupDuplex.Controls.Add(this.ckDuplex);
|
||||
this.groupDuplex.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.groupDuplex.Enabled = false;
|
||||
this.groupDuplex.Location = new System.Drawing.Point(9, 231);
|
||||
this.groupDuplex.Margin = new System.Windows.Forms.Padding(9, 9, 9, 9);
|
||||
this.groupDuplex.Name = "groupDuplex";
|
||||
this.groupDuplex.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.groupDuplex.Size = new System.Drawing.Size(241, 67);
|
||||
this.groupDuplex.TabIndex = 6;
|
||||
this.groupDuplex.TabStop = false;
|
||||
this.groupDuplex.Text = "Duplex";
|
||||
//
|
||||
// ckDuplex
|
||||
//
|
||||
this.ckDuplex.AutoSize = true;
|
||||
this.ckDuplex.Location = new System.Drawing.Point(21, 28);
|
||||
this.ckDuplex.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.ckDuplex.Name = "ckDuplex";
|
||||
this.ckDuplex.Size = new System.Drawing.Size(68, 19);
|
||||
this.ckDuplex.TabIndex = 0;
|
||||
this.ckDuplex.Text = "Enabled";
|
||||
this.ckDuplex.UseVisualStyleBackColor = true;
|
||||
this.ckDuplex.CheckedChanged += new System.EventHandler(this.ckDuplex_CheckedChanged);
|
||||
//
|
||||
// groupSize
|
||||
//
|
||||
this.groupSize.Controls.Add(this.comboSize);
|
||||
this.groupSize.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.groupSize.Enabled = false;
|
||||
this.groupSize.Location = new System.Drawing.Point(9, 157);
|
||||
this.groupSize.Margin = new System.Windows.Forms.Padding(9, 9, 9, 3);
|
||||
this.groupSize.Name = "groupSize";
|
||||
this.groupSize.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.groupSize.Size = new System.Drawing.Size(241, 62);
|
||||
this.groupSize.TabIndex = 5;
|
||||
this.groupSize.TabStop = false;
|
||||
this.groupSize.Text = "Size";
|
||||
//
|
||||
// comboSize
|
||||
//
|
||||
this.comboSize.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.comboSize.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboSize.FormattingEnabled = true;
|
||||
this.comboSize.Location = new System.Drawing.Point(21, 22);
|
||||
this.comboSize.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.comboSize.Name = "comboSize";
|
||||
this.comboSize.Size = new System.Drawing.Size(197, 23);
|
||||
this.comboSize.TabIndex = 0;
|
||||
this.comboSize.SelectedIndexChanged += new System.EventHandler(this.comboSize_SelectedIndexChanged);
|
||||
//
|
||||
// groupDepth
|
||||
//
|
||||
this.groupDepth.Controls.Add(this.comboDepth);
|
||||
this.groupDepth.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.groupDepth.Enabled = false;
|
||||
this.groupDepth.Location = new System.Drawing.Point(9, 83);
|
||||
this.groupDepth.Margin = new System.Windows.Forms.Padding(9, 9, 9, 3);
|
||||
this.groupDepth.Name = "groupDepth";
|
||||
this.groupDepth.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.groupDepth.Size = new System.Drawing.Size(241, 62);
|
||||
this.groupDepth.TabIndex = 4;
|
||||
this.groupDepth.TabStop = false;
|
||||
this.groupDepth.Text = "Depth";
|
||||
//
|
||||
// comboDepth
|
||||
//
|
||||
this.comboDepth.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.comboDepth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboDepth.FormattingEnabled = true;
|
||||
this.comboDepth.Location = new System.Drawing.Point(21, 22);
|
||||
this.comboDepth.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.comboDepth.Name = "comboDepth";
|
||||
this.comboDepth.Size = new System.Drawing.Size(197, 23);
|
||||
this.comboDepth.TabIndex = 0;
|
||||
this.comboDepth.SelectedIndexChanged += new System.EventHandler(this.comboDepth_SelectedIndexChanged);
|
||||
//
|
||||
// groupDPI
|
||||
//
|
||||
this.groupDPI.Controls.Add(this.comboDPI);
|
||||
this.groupDPI.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.groupDPI.Enabled = false;
|
||||
this.groupDPI.Location = new System.Drawing.Point(9, 9);
|
||||
this.groupDPI.Margin = new System.Windows.Forms.Padding(9, 9, 9, 3);
|
||||
this.groupDPI.Name = "groupDPI";
|
||||
this.groupDPI.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.groupDPI.Size = new System.Drawing.Size(241, 62);
|
||||
this.groupDPI.TabIndex = 0;
|
||||
this.groupDPI.TabStop = false;
|
||||
this.groupDPI.Text = "DPI";
|
||||
//
|
||||
// comboDPI
|
||||
//
|
||||
this.comboDPI.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.comboDPI.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboDPI.FormattingEnabled = true;
|
||||
this.comboDPI.Location = new System.Drawing.Point(21, 22);
|
||||
this.comboDPI.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.comboDPI.Name = "comboDPI";
|
||||
this.comboDPI.Size = new System.Drawing.Size(197, 23);
|
||||
this.comboDPI.TabIndex = 0;
|
||||
this.comboDPI.SelectedIndexChanged += new System.EventHandler(this.comboDPI_SelectedIndexChanged);
|
||||
//
|
||||
// btnAllSettings
|
||||
//
|
||||
this.btnAllSettings.Anchor = System.Windows.Forms.AnchorStyles.Top;
|
||||
this.btnAllSettings.Enabled = false;
|
||||
this.btnAllSettings.Location = new System.Drawing.Point(40, 356);
|
||||
this.btnAllSettings.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.btnAllSettings.Name = "btnAllSettings";
|
||||
this.btnAllSettings.Size = new System.Drawing.Size(178, 27);
|
||||
this.btnAllSettings.TabIndex = 7;
|
||||
this.btnAllSettings.Text = "Open driver settings";
|
||||
this.btnAllSettings.UseVisualStyleBackColor = true;
|
||||
this.btnAllSettings.Click += new System.EventHandler(this.btnAllSettings_Click);
|
||||
//
|
||||
// TestForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(936, 525);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Controls.Add(this.panelOptions);
|
||||
this.Controls.Add(this.toolStrip1);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.Name = "TestForm";
|
||||
this.Text = "Test Form";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.toolStrip1.ResumeLayout(false);
|
||||
this.toolStrip1.PerformLayout();
|
||||
this.panelOptions.ResumeLayout(false);
|
||||
this.groupDuplex.ResumeLayout(false);
|
||||
this.groupDuplex.PerformLayout();
|
||||
this.groupSize.ResumeLayout(false);
|
||||
this.groupDepth.ResumeLayout(false);
|
||||
this.groupDPI.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBox1;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
|
||||
private System.Windows.Forms.ToolStrip toolStrip1;
|
||||
private System.Windows.Forms.ToolStripDropDownButton btnSources;
|
||||
private System.Windows.Forms.ToolStripSeparator sepSourceList;
|
||||
private System.Windows.Forms.ToolStripMenuItem reloadSourcesListToolStripMenuItem;
|
||||
private System.Windows.Forms.TableLayoutPanel panelOptions;
|
||||
private System.Windows.Forms.GroupBox groupDPI;
|
||||
private System.Windows.Forms.GroupBox groupDepth;
|
||||
private System.Windows.Forms.GroupBox groupSize;
|
||||
private System.Windows.Forms.GroupBox groupDuplex;
|
||||
private System.Windows.Forms.ComboBox comboDPI;
|
||||
private System.Windows.Forms.ComboBox comboSize;
|
||||
private System.Windows.Forms.ComboBox comboDepth;
|
||||
private System.Windows.Forms.ToolStripButton btnStartCapture;
|
||||
private System.Windows.Forms.ToolStripButton btnStopScan;
|
||||
private System.Windows.Forms.ToolStripButton btnSaveImage;
|
||||
private System.Windows.Forms.CheckBox ckDuplex;
|
||||
private System.Windows.Forms.Button btnAllSettings;
|
||||
}
|
||||
}
|
||||
|
421
samples/Sample.Net5Winform/TestForm.cs
Normal file
421
samples/Sample.Net5Winform/TestForm.cs
Normal file
@ -0,0 +1,421 @@
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Sample.Net5Winform
|
||||
{
|
||||
public partial class TestForm : Form
|
||||
{
|
||||
ImageCodecInfo _tiffCodecInfo;
|
||||
TwainSession _twain;
|
||||
bool _stopScan;
|
||||
bool _loadingCaps;
|
||||
|
||||
|
||||
#region setup & cleanup
|
||||
|
||||
public TestForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
if (NTwain.PlatformInfo.Current.IsApp64Bit)
|
||||
{
|
||||
Text = Text + " (64bit)";
|
||||
}
|
||||
else
|
||||
{
|
||||
Text = Text + " (32bit)";
|
||||
}
|
||||
foreach (var enc in ImageCodecInfo.GetImageEncoders())
|
||||
{
|
||||
if (enc.MimeType == "image/tiff") { _tiffCodecInfo = enc; break; }
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
SetupTwain();
|
||||
|
||||
}
|
||||
|
||||
protected override void OnFormClosing(FormClosingEventArgs e)
|
||||
{
|
||||
if (_twain != null)
|
||||
{
|
||||
if (e.CloseReason == CloseReason.UserClosing && _twain.State > 4)
|
||||
{
|
||||
e.Cancel = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CleanupTwain();
|
||||
}
|
||||
}
|
||||
base.OnFormClosing(e);
|
||||
}
|
||||
|
||||
private void SetupTwain()
|
||||
{
|
||||
var appId = TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetEntryAssembly());
|
||||
_twain = new TwainSession(appId);
|
||||
_twain.StateChanged += (s, e) =>
|
||||
{
|
||||
PlatformInfo.Current.Log.Info("State changed to " + _twain.State + " on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||
};
|
||||
_twain.TransferError += (s, e) =>
|
||||
{
|
||||
PlatformInfo.Current.Log.Info("Got xfer error on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||
};
|
||||
_twain.DataTransferred += (s, e) =>
|
||||
{
|
||||
PlatformInfo.Current.Log.Info("Transferred data event on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||
|
||||
// example on getting ext image info
|
||||
var infos = e.GetExtImageInfo(ExtendedImageInfo.Camera).Where(it => it.ReturnCode == ReturnCode.Success);
|
||||
foreach (var it in infos)
|
||||
{
|
||||
var values = it.ReadValues();
|
||||
PlatformInfo.Current.Log.Info(string.Format("{0} = {1}", it.InfoID, values.FirstOrDefault()));
|
||||
break;
|
||||
}
|
||||
|
||||
// handle image data
|
||||
Image img = null;
|
||||
if (e.NativeData != IntPtr.Zero)
|
||||
{
|
||||
var stream = e.GetNativeImageStream();
|
||||
if (stream != null)
|
||||
{
|
||||
img = Image.FromStream(stream);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(e.FileDataPath))
|
||||
{
|
||||
img = new Bitmap(e.FileDataPath);
|
||||
}
|
||||
if (img != null)
|
||||
{
|
||||
this.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (pictureBox1.Image != null)
|
||||
{
|
||||
pictureBox1.Image.Dispose();
|
||||
pictureBox1.Image = null;
|
||||
}
|
||||
pictureBox1.Image = img;
|
||||
}));
|
||||
}
|
||||
};
|
||||
_twain.SourceDisabled += (s, e) =>
|
||||
{
|
||||
PlatformInfo.Current.Log.Info("Source disabled event on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||
this.BeginInvoke(new Action(() =>
|
||||
{
|
||||
btnStopScan.Enabled = false;
|
||||
btnStartCapture.Enabled = true;
|
||||
panelOptions.Enabled = true;
|
||||
LoadSourceCaps();
|
||||
}));
|
||||
};
|
||||
_twain.TransferReady += (s, e) =>
|
||||
{
|
||||
PlatformInfo.Current.Log.Info("Transferr ready event on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||
e.CancelAll = _stopScan;
|
||||
};
|
||||
|
||||
// either set sync context and don't worry about threads during events,
|
||||
// or don't and use control.invoke during the events yourself
|
||||
PlatformInfo.Current.Log.Info("Setup thread = " + Thread.CurrentThread.ManagedThreadId);
|
||||
_twain.SynchronizationContext = SynchronizationContext.Current;
|
||||
if (_twain.State < 3)
|
||||
{
|
||||
// use this for internal msg loop
|
||||
_twain.Open();
|
||||
// use this to hook into current app loop
|
||||
//_twain.Open(new WindowsFormsMessageLoopHook(this.Handle));
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanupTwain()
|
||||
{
|
||||
if (_twain.State == 4)
|
||||
{
|
||||
_twain.CurrentSource.Close();
|
||||
}
|
||||
if (_twain.State == 3)
|
||||
{
|
||||
_twain.Close();
|
||||
}
|
||||
|
||||
if (_twain.State > 2)
|
||||
{
|
||||
// normal close down didn't work, do hard kill
|
||||
_twain.ForceStepDown(2);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region toolbar
|
||||
|
||||
private void btnSources_DropDownOpening(object sender, EventArgs e)
|
||||
{
|
||||
if (btnSources.DropDownItems.Count == 2)
|
||||
{
|
||||
ReloadSourceList();
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadSourcesListToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ReloadSourceList();
|
||||
}
|
||||
|
||||
private void ReloadSourceList()
|
||||
{
|
||||
if (_twain.State >= 3)
|
||||
{
|
||||
while (btnSources.DropDownItems.IndexOf(sepSourceList) > 0)
|
||||
{
|
||||
var first = btnSources.DropDownItems[0];
|
||||
first.Click -= SourceMenuItem_Click;
|
||||
btnSources.DropDownItems.Remove(first);
|
||||
}
|
||||
foreach (var src in _twain)
|
||||
{
|
||||
var srcBtn = new ToolStripMenuItem(src.Name);
|
||||
srcBtn.Tag = src;
|
||||
srcBtn.Click += SourceMenuItem_Click;
|
||||
srcBtn.Checked = _twain.CurrentSource != null && _twain.CurrentSource.Name == src.Name;
|
||||
btnSources.DropDownItems.Insert(0, srcBtn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SourceMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
// do nothing if source is enabled
|
||||
if (_twain.State > 4) { return; }
|
||||
|
||||
if (_twain.State == 4) { _twain.CurrentSource.Close(); }
|
||||
|
||||
foreach (var btn in btnSources.DropDownItems)
|
||||
{
|
||||
var srcBtn = btn as ToolStripMenuItem;
|
||||
if (srcBtn != null) { srcBtn.Checked = false; }
|
||||
}
|
||||
|
||||
var curBtn = (sender as ToolStripMenuItem);
|
||||
var src = curBtn.Tag as DataSource;
|
||||
if (src.Open() == ReturnCode.Success)
|
||||
{
|
||||
curBtn.Checked = true;
|
||||
btnStartCapture.Enabled = true;
|
||||
LoadSourceCaps();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnStartCapture_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_twain.State == 4)
|
||||
{
|
||||
//_twain.CurrentSource.CapXferCount.Set(4);
|
||||
|
||||
_stopScan = false;
|
||||
|
||||
if (_twain.CurrentSource.Capabilities.CapUIControllable.IsSupported)//.SupportedCaps.Contains(CapabilityId.CapUIControllable))
|
||||
{
|
||||
// hide scanner ui if possible
|
||||
if (_twain.CurrentSource.Enable(SourceEnableMode.NoUI, false, this.Handle) == ReturnCode.Success)
|
||||
{
|
||||
btnStopScan.Enabled = true;
|
||||
btnStartCapture.Enabled = false;
|
||||
panelOptions.Enabled = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_twain.CurrentSource.Enable(SourceEnableMode.ShowUI, true, this.Handle) == ReturnCode.Success)
|
||||
{
|
||||
btnStopScan.Enabled = true;
|
||||
btnStartCapture.Enabled = false;
|
||||
panelOptions.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnStopScan_Click(object sender, EventArgs e)
|
||||
{
|
||||
_stopScan = true;
|
||||
}
|
||||
|
||||
private void btnSaveImage_Click(object sender, EventArgs e)
|
||||
{
|
||||
var img = pictureBox1.Image;
|
||||
|
||||
if (img != null)
|
||||
{
|
||||
switch (img.PixelFormat)
|
||||
{
|
||||
case PixelFormat.Format1bppIndexed:
|
||||
saveFileDialog1.Filter = "tiff files|*.tif";
|
||||
break;
|
||||
default:
|
||||
saveFileDialog1.Filter = "png files|*.png";
|
||||
break;
|
||||
}
|
||||
|
||||
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
if (saveFileDialog1.FileName.EndsWith(".tif", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
EncoderParameters tiffParam = new EncoderParameters(1);
|
||||
|
||||
tiffParam.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
|
||||
|
||||
pictureBox1.Image.Save(saveFileDialog1.FileName, _tiffCodecInfo, tiffParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
pictureBox1.Image.Save(saveFileDialog1.FileName, ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region cap control
|
||||
|
||||
|
||||
private void LoadSourceCaps()
|
||||
{
|
||||
var src = _twain.CurrentSource;
|
||||
_loadingCaps = true;
|
||||
|
||||
//var test = src.SupportedCaps;
|
||||
|
||||
if (groupDepth.Enabled = src.Capabilities.ICapPixelType.IsSupported)
|
||||
{
|
||||
LoadDepth(src.Capabilities.ICapPixelType);
|
||||
}
|
||||
if (groupDPI.Enabled = src.Capabilities.ICapXResolution.IsSupported && src.Capabilities.ICapYResolution.IsSupported)
|
||||
{
|
||||
LoadDPI(src.Capabilities.ICapXResolution);
|
||||
}
|
||||
// TODO: find out if this is how duplex works or also needs the other option
|
||||
if (groupDuplex.Enabled = src.Capabilities.CapDuplexEnabled.IsSupported)
|
||||
{
|
||||
LoadDuplex(src.Capabilities.CapDuplexEnabled);
|
||||
}
|
||||
if (groupSize.Enabled = src.Capabilities.ICapSupportedSizes.IsSupported)
|
||||
{
|
||||
LoadPaperSize(src.Capabilities.ICapSupportedSizes);
|
||||
}
|
||||
btnAllSettings.Enabled = src.Capabilities.CapEnableDSUIOnly.IsSupported;
|
||||
_loadingCaps = false;
|
||||
}
|
||||
|
||||
private void LoadPaperSize(ICapWrapper<SupportedSize> cap)
|
||||
{
|
||||
var list = cap.GetValues().ToList();
|
||||
comboSize.DataSource = list;
|
||||
var cur = cap.GetCurrent();
|
||||
if (list.Contains(cur))
|
||||
{
|
||||
comboSize.SelectedItem = cur;
|
||||
}
|
||||
var labelTest = cap.GetLabel();
|
||||
if (!string.IsNullOrEmpty(labelTest))
|
||||
{
|
||||
groupSize.Text = labelTest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void LoadDuplex(ICapWrapper<BoolType> cap)
|
||||
{
|
||||
ckDuplex.Checked = cap.GetCurrent() == BoolType.True;
|
||||
}
|
||||
|
||||
|
||||
private void LoadDPI(ICapWrapper<TWFix32> cap)
|
||||
{
|
||||
// only allow dpi of certain values for those source that lists everything
|
||||
var list = cap.GetValues().Where(dpi => (dpi % 50) == 0).ToList();
|
||||
comboDPI.DataSource = list;
|
||||
var cur = cap.GetCurrent();
|
||||
if (list.Contains(cur))
|
||||
{
|
||||
comboDPI.SelectedItem = cur;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadDepth(ICapWrapper<PixelType> cap)
|
||||
{
|
||||
var list = cap.GetValues().ToList();
|
||||
comboDepth.DataSource = list;
|
||||
var cur = cap.GetCurrent();
|
||||
if (list.Contains(cur))
|
||||
{
|
||||
comboDepth.SelectedItem = cur;
|
||||
}
|
||||
var labelTest = cap.GetLabel();
|
||||
if (!string.IsNullOrEmpty(labelTest))
|
||||
{
|
||||
groupDepth.Text = labelTest;
|
||||
}
|
||||
}
|
||||
|
||||
private void comboSize_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
var sel = (SupportedSize)comboSize.SelectedItem;
|
||||
_twain.CurrentSource.Capabilities.ICapSupportedSizes.SetValue(sel);
|
||||
}
|
||||
}
|
||||
|
||||
private void comboDepth_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
var sel = (PixelType)comboDepth.SelectedItem;
|
||||
_twain.CurrentSource.Capabilities.ICapPixelType.SetValue(sel);
|
||||
}
|
||||
}
|
||||
|
||||
private void comboDPI_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
var sel = (TWFix32)comboDPI.SelectedItem;
|
||||
_twain.CurrentSource.Capabilities.ICapXResolution.SetValue(sel);
|
||||
_twain.CurrentSource.Capabilities.ICapYResolution.SetValue(sel);
|
||||
}
|
||||
}
|
||||
|
||||
private void ckDuplex_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
_twain.CurrentSource.Capabilities.CapDuplexEnabled.SetValue(ckDuplex.Checked ? BoolType.True : BoolType.False);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnAllSettings_Click(object sender, EventArgs e)
|
||||
{
|
||||
_twain.CurrentSource.Enable(SourceEnableMode.ShowUIOnly, true, this.Handle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
1054
samples/Sample.Net5Winform/TestForm.resx
Normal file
1054
samples/Sample.Net5Winform/TestForm.resx
Normal file
File diff suppressed because it is too large
Load Diff
BIN
samples/Sample.Net5Winform/scanner.ico
Normal file
BIN
samples/Sample.Net5Winform/scanner.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<PackageId>NTwain</PackageId>
|
||||
<Description>Library containing the TWAIN API for dotnet.</Description>
|
||||
<TargetFrameworks>net35;net40</TargetFrameworks>
|
||||
<TargetFrameworks>net5.0-windows;net40;net35</TargetFrameworks>
|
||||
<PackageProjectUrl>https://github.com/soukoku/ntwain</PackageProjectUrl>
|
||||
<PackageTags>twain scan</PackageTags>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
@ -29,15 +29,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net35'">
|
||||
|
Loading…
Reference in New Issue
Block a user