Reorged source tree.

This commit is contained in:
soukoku
2015-03-15 17:36:17 -04:00
parent 2ebe3ced0f
commit 54a913893a
137 changed files with 57 additions and 55 deletions

View File

@@ -0,0 +1,19 @@
using System;
using System.Windows.Forms;
namespace Sample.Winform
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Sample.Winform")]
[assembly: AssemblyDescription("Winform app for quick testing implementations in the TWAIN lib.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Yin-Chun Wang")]
[assembly: AssemblyProduct("Sample.Winform")]
[assembly: AssemblyCopyright("Copyright © Yin-Chun Wang 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("81c482ce-db1a-45ac-8db8-86a784082c1b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Sample.Winform.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Sample.Winform.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Sample.Winform.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View File

@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4FC243F1-318E-4FA9-9EBD-2CA3A8F35425}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample.Winform</RootNamespace>
<AssemblyName>Sample.Winform</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>scanner.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="TestForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TestForm.Designer.cs">
<DependentUpon>TestForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="TestForm.resx">
<DependentUpon>TestForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\NTwain.Net35\NTwain.Net35.csproj">
<Project>{2e965494-94b0-4ec7-960c-24e5d7d04278}</Project>
<Name>NTwain.Net35</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="scanner.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,329 @@
namespace Sample.Winform
{
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(222, 25);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(580, 430);
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(802, 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.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, 20F));
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.panelOptions.Size = new System.Drawing.Size(222, 430);
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(8, 203);
this.groupDuplex.Margin = new System.Windows.Forms.Padding(8);
this.groupDuplex.Name = "groupDuplex";
this.groupDuplex.Size = new System.Drawing.Size(206, 58);
this.groupDuplex.TabIndex = 6;
this.groupDuplex.TabStop = false;
this.groupDuplex.Text = "Duplex";
//
// ckDuplex
//
this.ckDuplex.AutoSize = true;
this.ckDuplex.Location = new System.Drawing.Point(18, 24);
this.ckDuplex.Name = "ckDuplex";
this.ckDuplex.Size = new System.Drawing.Size(65, 17);
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(8, 138);
this.groupSize.Margin = new System.Windows.Forms.Padding(8, 8, 8, 3);
this.groupSize.Name = "groupSize";
this.groupSize.Size = new System.Drawing.Size(206, 54);
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(18, 19);
this.comboSize.Name = "comboSize";
this.comboSize.Size = new System.Drawing.Size(169, 21);
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(8, 73);
this.groupDepth.Margin = new System.Windows.Forms.Padding(8, 8, 8, 3);
this.groupDepth.Name = "groupDepth";
this.groupDepth.Size = new System.Drawing.Size(206, 54);
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(18, 19);
this.comboDepth.Name = "comboDepth";
this.comboDepth.Size = new System.Drawing.Size(169, 21);
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(8, 8);
this.groupDPI.Margin = new System.Windows.Forms.Padding(8, 8, 8, 3);
this.groupDPI.Name = "groupDPI";
this.groupDPI.Size = new System.Drawing.Size(206, 54);
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(18, 19);
this.comboDPI.Name = "comboDPI";
this.comboDPI.Size = new System.Drawing.Size(169, 21);
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(34, 312);
this.btnAllSettings.Name = "btnAllSettings";
this.btnAllSettings.Size = new System.Drawing.Size(153, 23);
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(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(802, 455);
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.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;
}
}

View File

@@ -0,0 +1,422 @@
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.Winform
{
sealed 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) =>
{
Debug.WriteLine("State changed to " + _twain.State + " on thread " + Thread.CurrentThread.ManagedThreadId);
};
_twain.TransferError += (s, e) =>
{
Debug.WriteLine("Got xfer error on thread " + Thread.CurrentThread.ManagedThreadId);
};
_twain.DataTransferred += (s, e) =>
{
Debug.WriteLine("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();
Debug.WriteLine(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) =>
{
Debug.WriteLine("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) =>
{
Debug.WriteLine("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
Debug.WriteLine("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();
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();
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
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v2.0.50727" sku="Client"/></startup></configuration>

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB