mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
More cleanup.
This commit is contained in:
parent
b68dcbf64f
commit
169faa7e08
@ -7,8 +7,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{4CE0B9
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
LICENSE.txt = LICENSE.txt
|
||||
README.md = README.md
|
||||
Spec\TWAIN-2.4-Specification.pdf = Spec\TWAIN-2.4-Specification.pdf
|
||||
Spec\twain2.4.h = Spec\twain2.4.h
|
||||
twain-doc\TWAIN-2.4-Specification.pdf = twain-doc\TWAIN-2.4-Specification.pdf
|
||||
twain-doc\twain2.4.h = twain-doc\twain2.4.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
|
@ -1,107 +0,0 @@
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
||||
namespace Sample
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
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("Tester.Console")]
|
||||
[assembly: AssemblyDescription("Console app for quick testing implementations in the TWAIN lib.")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Yin-Chun Wang")]
|
||||
[assembly: AssemblyProduct("Tester.Console")]
|
||||
[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("c27df82d-5be9-4396-8905-0af6ea6e63cd")]
|
||||
|
||||
// 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")]
|
@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{12D761EF-68DF-41CE-92EF-0C7AE81857A3}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Sample</RootNamespace>
|
||||
<AssemblyName>Sample.Console</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<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|AnyCPU' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj">
|
||||
<Project>{0c5a6fb1-0282-4d61-8354-68deb1515001}</Project>
|
||||
<Name>NTwain</Name>
|
||||
</ProjectReference>
|
||||
</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>
|
@ -1,39 +0,0 @@
|
||||
<Application x:Class="Sample.WPF.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="Launcher.xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<!-- Launcher Style, anything you won't use goes -->
|
||||
<Style TargetType="{x:Type Rectangle}" />
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/ModernWpf;component/Themes/BaseValues.xaml" />
|
||||
<ResourceDictionary Source="/ModernWpf;component/Themes/ColorLight.xaml" />
|
||||
<ResourceDictionary Source="/ModernWpf;component/Themes/ModernStyles.xaml" />
|
||||
|
||||
<ResourceDictionary>
|
||||
<Style x:Key="AppWindow" TargetType="Window" BasedOn="{StaticResource ModernWindow}"/>
|
||||
<Style x:Key="AppListBoxItem" TargetType="ListBoxItem" BasedOn="{StaticResource ModernListBoxItem}">
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource ModernBackground2}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource ModernBackground2}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource ModernForeground}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource ModernAccent}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="AppListBox" TargetType="ListBox" BasedOn="{StaticResource ModernListBox}">
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource AppListBoxItem}"/>
|
||||
<Setter Property="BorderThickness" Value="0 1 1 0"/>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
@ -1,22 +0,0 @@
|
||||
using ModernWpf;
|
||||
using System.Windows;
|
||||
|
||||
namespace Sample.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public App()
|
||||
{
|
||||
UIHooks.EnableHighDpiSupport();
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
Theme.ApplyTheme(ThemeColor.Light, Accent.Green);
|
||||
base.OnStartup(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<Window x:Class="Sample.WPF.Launcher"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:twain="clr-namespace:NTwain;assembly=NTwain"
|
||||
Title="Scan Launcher" Height="200" Width="250"
|
||||
ResizeMode="NoResize" Style="{StaticResource AppWindow}">
|
||||
<Grid>
|
||||
<StackPanel VerticalAlignment="Center">
|
||||
<CheckBox DataContext="{x:Static twain:PlatformInfo.Current}"
|
||||
IsChecked="{Binding PreferNewDSM}"
|
||||
IsEnabled="{Binding IsWindows, Mode=OneWay}"
|
||||
Content="Prefer new DSM"
|
||||
HorizontalAlignment="Center"></CheckBox>
|
||||
<Button Content="Open scan window" Click="Button_Click" Margin="4 0"></Button>
|
||||
<TextBlock Text="This is to test opening/closing multiple twain sessions in an app" Margin="8"
|
||||
TextWrapping="Wrap"></TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Sample.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for Launcher.xaml
|
||||
/// </summary>
|
||||
public partial class Launcher : Window
|
||||
{
|
||||
public Launcher()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
new MainWindow().ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
<Window x:Class="Sample.WPF.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:modern="http://modernwpf"
|
||||
xmlns:proj="clr-namespace:Sample.WPF"
|
||||
Title="{Binding AppTitle}"
|
||||
Height="600" Width="900" ResizeMode="CanResizeWithGrip"
|
||||
x:Name="theWindow"
|
||||
Style="{StaticResource AppWindow}">
|
||||
<Window.Resources>
|
||||
<proj:TwainVM x:Key="vm"></proj:TwainVM>
|
||||
</Window.Resources>
|
||||
<Window.DataContext>
|
||||
<StaticResource ResourceKey="vm"></StaticResource>
|
||||
</Window.DataContext>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Content="Sources"></Label>
|
||||
<ListBox x:Name="SrcList" Grid.Row="1" Grid.RowSpan="2" Width="150"
|
||||
ItemsSource="{Binding DataSources}"
|
||||
SelectedItem="{Binding SelectedSource}"
|
||||
Style="{StaticResource AppListBox}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Name}" TextWrapping="Wrap"></TextBlock>
|
||||
<TextBlock Text="{Binding Version, StringFormat='Version {0}'}" TextWrapping="Wrap" Foreground="{DynamicResource ModernForeground2}"
|
||||
Margin="8 0 0 0"/>
|
||||
<TextBlock Text="{Binding Protocol, StringFormat='TWAIN {0}'}" Foreground="{DynamicResource ModernForeground2}"
|
||||
Margin="8 0 0 0"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Grid.Column="1">
|
||||
<Label Content="Caps" Grid.Column="1"></Label>
|
||||
<Button Content="Save Reported" Command="{Binding SaveCapValuesCommand}" DataContext="{Binding SelectedSource}"></Button>
|
||||
</StackPanel>
|
||||
<TextBox Text="{Binding CapFilter, UpdateSourceTrigger=PropertyChanged}" DataContext="{Binding SelectedSource}"
|
||||
Grid.Column="1" Grid.Row="1"
|
||||
modern:TextBoxUI.WatermarkText="Find cap name"></TextBox>
|
||||
<ListBox x:Name="CapList" Grid.Row="2" Grid.Column="1" Width="150"
|
||||
DataContext="{Binding SelectedSource}"
|
||||
ItemsSource="{Binding Caps}"
|
||||
SelectionChanged="CapList_SelectionChanged"
|
||||
Style="{StaticResource AppListBox}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Name}" ></TextBlock>
|
||||
<TextBlock Text="{Binding Supports}" TextWrapping="Wrap" Foreground="{DynamicResource ModernForeground2}"
|
||||
FontStyle="Italic"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<Label Content="Cap values" Grid.Column="2"></Label>
|
||||
<ListBox x:Name="CapDetailList" Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" MinWidth="100"
|
||||
SelectionChanged="CapDetailList_SelectionChanged"
|
||||
ScrollViewer.CanContentScroll="True"
|
||||
Style="{StaticResource AppListBox}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}"></TextBlock>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Grid.Column="3" >
|
||||
<Label Content="State:"></Label>
|
||||
<TextBlock Text="{Binding State}"></TextBlock>
|
||||
<Button Content="S_ettings" Command="{Binding ShowDriverCommand}"></Button>
|
||||
<Button Content="S_tart" Command="{Binding CaptureCommand}"></Button>
|
||||
<CheckBox Content="Show _UI" IsChecked="{Binding ShowUI}"></CheckBox>
|
||||
<Slider Maximum="{Binding MaxThumbnailSize}" Minimum="{Binding MinThumbnailSize}"
|
||||
Value="{Binding ThumbnailSize}" Width="100" LargeChange="20" SmallChange="10"
|
||||
VerticalAlignment="Center"
|
||||
ToolTip="{Binding ThumbnailSize}"></Slider>
|
||||
<TextBlock Text="{Binding CapturedImages.Count, StringFormat='{}{0} pages'}"></TextBlock>
|
||||
<Button Content="_Clear pages" Command="{Binding ClearCommand}"></Button>
|
||||
<!--<Button Content="_Save" Command="{Binding SaveCommand}"></Button>-->
|
||||
</StackPanel>
|
||||
|
||||
<ListBox Grid.Row="1" Grid.RowSpan="2" Grid.Column="3"
|
||||
ItemsSource="{Binding CapturedImages}">
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel ScrollViewer.HorizontalScrollBarVisibility="Disabled"></WrapPanel>
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Padding="4">
|
||||
<Image Stretch="Uniform"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
Width="{Binding ElementName=theWindow, Path=DataContext.ThumbnailSize}"
|
||||
Height="{Binding ElementName=theWindow, Path=DataContext.ThumbnailSize}"
|
||||
Source="{Binding}"></Image>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</Window>
|
@ -1,127 +0,0 @@
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using ModernWpf;
|
||||
using ModernWpf.Controls;
|
||||
using ModernWpf.Messages;
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace Sample.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
TwainVM _twainVM;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
if (!DesignerProperties.GetIsInDesignMode(this))
|
||||
{
|
||||
_twainVM = this.DataContext as TwainVM;
|
||||
_twainVM.PropertyChanged += _twainVM_PropertyChanged;
|
||||
Messenger.Default.Register<RefreshCommandsMessage>(this, m => m.HandleIt());
|
||||
Messenger.Default.Register<ChooseFileMessage>(this, m =>
|
||||
{
|
||||
m.HandleWithPlatform(this);
|
||||
});
|
||||
Messenger.Default.Register<MessageBoxMessage>(this, msg =>
|
||||
{
|
||||
if (Dispatcher.CheckAccess())
|
||||
{
|
||||
msg.HandleWithModern(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
msg.HandleWithModern(this);
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void _twainVM_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "State")
|
||||
{
|
||||
if (_twainVM.State == 5)
|
||||
{
|
||||
Theme.ApplyTheme(ThemeColor.Light, Accent.Orange);
|
||||
}
|
||||
else if (_twainVM.State == 4)
|
||||
{
|
||||
Theme.ApplyTheme(ThemeColor.Light, Accent.Green);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = _twainVM.State > 4;
|
||||
base.OnClosing(e);
|
||||
}
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
Messenger.Default.Unregister(this);
|
||||
_twainVM.CloseDown();
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
protected override void OnSourceInitialized(EventArgs e)
|
||||
{
|
||||
base.OnSourceInitialized(e);
|
||||
_twainVM.WindowHandle = new WindowInteropHelper(this).Handle;
|
||||
|
||||
}
|
||||
|
||||
private void CapList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var capVM = CapList.SelectedItem as CapVM;
|
||||
if (capVM != null)
|
||||
{
|
||||
CapDetailList.ItemsSource = capVM.Get();
|
||||
CapDetailList.SelectedItem = capVM.GetCurrent();
|
||||
}
|
||||
else
|
||||
{
|
||||
CapDetailList.ItemsSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void CapDetailList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var capVM = CapList.SelectedItem as CapVM;
|
||||
if (capVM != null)
|
||||
{
|
||||
if (capVM.Supports.HasFlag(QuerySupports.Set))
|
||||
{
|
||||
try
|
||||
{
|
||||
capVM.Set(CapDetailList.SelectedItem);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is TargetInvocationException)
|
||||
{
|
||||
ex = ex.InnerException;
|
||||
}
|
||||
ModernMessageBox.Show(this, ex.Message, "Cannot Set", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
// 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.WPF")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Yin-Chun Wang")]
|
||||
[assembly: AssemblyProduct("Sample.WPF")]
|
||||
[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)]
|
||||
|
||||
//In order to begin building localizable applications, set
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||
//the line below to match the UICulture setting in the project file.
|
||||
|
||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
|
||||
|
||||
// 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")]
|
||||
|
||||
[assembly: DisableDpiAwareness]
|
63
samples/Sample.WPF/Properties/Resources.Designer.cs
generated
63
samples/Sample.WPF/Properties/Resources.Designer.cs
generated
@ -1,63 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <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.WPF.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.WPF.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
<?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>
|
26
samples/Sample.WPF/Properties/Settings.Designer.cs
generated
26
samples/Sample.WPF/Properties/Settings.Designer.cs
generated
@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <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.WPF.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
@ -1,172 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Sample.WPF</RootNamespace>
|
||||
<AssemblyName>Sample.WPF</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<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>
|
||||
<UseVSHostingProcess>true</UseVSHostingProcess>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>scanner.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="GalaSoft.MvvmLight, Version=5.3.0.19038, Culture=neutral, PublicKeyToken=0e453835af4ee6ce, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\MvvmLightLibs.5.3.0.0\lib\net40\GalaSoft.MvvmLight.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.3.0.19026, Culture=neutral, PublicKeyToken=f46ff315b1088208, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\MvvmLightLibs.5.3.0.0\lib\net40\GalaSoft.MvvmLight.Extras.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.WindowsAPICodePack-Core.1.1.0.2\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.WindowsAPICodePack.Shell">
|
||||
<HintPath>..\..\packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.WindowsAPICodePack.ShellExtensions">
|
||||
<HintPath>..\..\packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ModernWpf, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c99d0cfbea7491ef, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\ModernWpf.2.0.0-alpha94\lib\net40-Client\ModernWpf.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ModernWpf.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c99d0cfbea7491ef, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\ModernWpf.Core.2.0.0-alpha96\lib\net40-Client\ModernWpf.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\MvvmLightLibs.5.3.0.0\lib\net40\System.Windows.Interactivity.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Launcher.xaml.cs">
|
||||
<DependentUpon>Launcher.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ViewModels\TwainVM.cs" />
|
||||
<Page Include="Launcher.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ViewModels\CapVM.cs" />
|
||||
<Compile Include="ViewModels\DataSourceVM.cs" />
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="app.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<AppDesigner Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj">
|
||||
<Project>{0c5a6fb1-0282-4d61-8354-68deb1515001}</Project>
|
||||
<Name>NTwain</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>
|
@ -1,100 +0,0 @@
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Sample.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Wraps a capability as a view model.
|
||||
/// </summary>
|
||||
class CapVM
|
||||
{
|
||||
DataSource _ds;
|
||||
object _wrapper;
|
||||
MethodInfo _getMethod;
|
||||
MethodInfo _getCurrentMethod;
|
||||
MethodInfo _setMethod;
|
||||
|
||||
public CapVM(DataSource ds, CapabilityId cap)
|
||||
{
|
||||
_ds = ds;
|
||||
Cap = cap;
|
||||
|
||||
|
||||
var capName = cap.ToString();
|
||||
var wrapProperty = ds.Capabilities.GetType().GetProperty(capName);
|
||||
if (wrapProperty != null)
|
||||
{
|
||||
_wrapper = wrapProperty.GetGetMethod().Invoke(ds.Capabilities, null);
|
||||
var wrapperType = _wrapper.GetType();
|
||||
_getMethod = wrapperType.GetMethod("GetValues");
|
||||
_getCurrentMethod = wrapperType.GetMethod("GetCurrent");
|
||||
_setMethod = wrapperType.GetMethods().FirstOrDefault(m => m.Name == "SetValue");
|
||||
}
|
||||
|
||||
var supportTest = ds.Capabilities.QuerySupport(cap);
|
||||
if (supportTest.HasValue)
|
||||
{
|
||||
Supports = supportTest.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_wrapper != null)
|
||||
{
|
||||
var wrapperType = _wrapper.GetType();
|
||||
QuerySupports? supports = (QuerySupports?)wrapperType.GetProperty("SupportedActions").GetGetMethod().Invoke(_wrapper, null);
|
||||
Supports = supports.GetValueOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable Get()
|
||||
{
|
||||
if (_getMethod == null)
|
||||
{
|
||||
return _ds.Capabilities.GetValues(Cap);
|
||||
}
|
||||
return _getMethod.Invoke(_wrapper, null) as IEnumerable;
|
||||
}
|
||||
public object GetCurrent()
|
||||
{
|
||||
if (_getMethod == null)
|
||||
{
|
||||
return _ds.Capabilities.GetCurrent(Cap);
|
||||
}
|
||||
return _getCurrentMethod.Invoke(_wrapper, null);
|
||||
}
|
||||
public void Set(object value)
|
||||
{
|
||||
if (_setMethod != null && value != null)
|
||||
{
|
||||
_setMethod.Invoke(_wrapper, new object[] { value });
|
||||
}
|
||||
}
|
||||
|
||||
public CapabilityId Cap { get; private set; }
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Cap > CapabilityId.CustomBase)
|
||||
{
|
||||
return "[CustomBase]+" + ((int)Cap - (int)CapabilityId.CustomBase);
|
||||
}
|
||||
return Cap.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public QuerySupports Supports { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using ModernWpf.Messages;
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Sample.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Wraps a data source as view model.
|
||||
/// </summary>
|
||||
class DataSourceVM : ViewModelBase
|
||||
{
|
||||
public DataSource DS { get; set; }
|
||||
|
||||
public string Name { get { return DS.Name; } }
|
||||
public string Version { get { return DS.Version.Info; } }
|
||||
public string Protocol { get { return DS.ProtocolVersion.ToString(); } }
|
||||
|
||||
ICollectionView _capView;
|
||||
public DataSourceVM()
|
||||
{
|
||||
Caps = new ObservableCollection<CapVM>();
|
||||
_capView = CollectionViewSource.GetDefaultView(Caps);
|
||||
_capView.SortDescriptions.Add(new System.ComponentModel.SortDescription("Name", System.ComponentModel.ListSortDirection.Ascending));
|
||||
_capView.Filter = FilterCapRoutine;
|
||||
}
|
||||
|
||||
private bool FilterCapRoutine(object obj)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(CapFilter))
|
||||
{
|
||||
var vm = obj as CapVM;
|
||||
if (vm != null)
|
||||
{
|
||||
return vm.Name.IndexOf(CapFilter, System.StringComparison.OrdinalIgnoreCase) > -1;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
Caps.Clear();
|
||||
var rc = DS.Open();
|
||||
//rc = DGControl.Status.Get(dsId, ref stat);
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
foreach (var c in DS.Capabilities.CapSupportedCaps.GetValues().Select(o => new CapVM(DS, o)))
|
||||
{
|
||||
Caps.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _capFilter;
|
||||
|
||||
public string CapFilter
|
||||
{
|
||||
get { return _capFilter; }
|
||||
set
|
||||
{
|
||||
_capFilter = value;
|
||||
_capView.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<CapVM> Caps { get; private set; }
|
||||
|
||||
private ICommand _saveCapCommand;
|
||||
|
||||
public ICommand SaveCapValuesCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _saveCapCommand ?? (_saveCapCommand = new RelayCommand(() =>
|
||||
{
|
||||
Messenger.Default.Send(new ChooseFileMessage(files =>
|
||||
{
|
||||
StringBuilder report = new StringBuilder();
|
||||
report.Append("Cap values for TWAIN device ").AppendLine(DS.Name);
|
||||
report.Append("Generated on ").AppendLine(DateTime.Now.ToString("yyyy/MM/dd hh:mm tt")).AppendLine();
|
||||
|
||||
foreach (CapVM cap in _capView)
|
||||
{
|
||||
report.Append(cap.Name).AppendLine(":");
|
||||
try
|
||||
{
|
||||
report.Append('\t').Append("Supports: ").Append(cap.Supports).AppendLine();
|
||||
report.Append('\t').Append("Values: ");
|
||||
foreach (var v in cap.Get())
|
||||
{
|
||||
report.Append(v).Append(',');
|
||||
}
|
||||
report.AppendLine();
|
||||
report.Append('\t').Append("Current: ").Append(cap.GetCurrent()).AppendLine();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
report.Append('\t').Append("Failed: ").Append(ex.Message).AppendLine();
|
||||
}
|
||||
report.AppendLine();
|
||||
}
|
||||
|
||||
File.WriteAllText(files.First(), report.ToString());
|
||||
|
||||
using (Process.Start(files.First())) { }
|
||||
})
|
||||
{
|
||||
Caption = "Choose Save File",
|
||||
Filters = "Text files|*.txt",
|
||||
InitialFileName = DS.Name + " capability",
|
||||
Purpose = FilePurpose.Save,
|
||||
});
|
||||
}, () => DS.IsOpen));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,369 +0,0 @@
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using ModernWpf.Messages;
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace Sample.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Wraps the twain session as a view model for databinding.
|
||||
/// </summary>
|
||||
class TwainVM : ViewModelBase
|
||||
{
|
||||
public TwainVM()
|
||||
{
|
||||
DataSources = new ObservableCollection<DataSourceVM>();
|
||||
CapturedImages = new ObservableCollection<ImageSource>();
|
||||
|
||||
//this.SynchronizationContext = SynchronizationContext.Current;
|
||||
var appId = TWIdentity.CreateFromAssembly(DataGroups.Image | DataGroups.Audio, Assembly.GetEntryAssembly());
|
||||
_session = new TwainSession(appId);
|
||||
_session.TransferError += _session_TransferError;
|
||||
_session.TransferReady += _session_TransferReady;
|
||||
_session.DataTransferred += _session_DataTransferred;
|
||||
_session.SourceDisabled += _session_SourceDisabled;
|
||||
_session.StateChanged += (s, e) => { RaisePropertyChanged(() => State); };
|
||||
}
|
||||
|
||||
TwainSession _session;
|
||||
|
||||
#region properties
|
||||
|
||||
public string AppTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (NTwain.PlatformInfo.Current.IsApp64Bit)
|
||||
{
|
||||
return "TWAIN Data Source Tester (64bit)";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "TWAIN Data Source Tester (32bit)";
|
||||
}
|
||||
}
|
||||
}
|
||||
public ObservableCollection<DataSourceVM> DataSources { get; private set; }
|
||||
private DataSourceVM _selectedSource;
|
||||
|
||||
public DataSourceVM SelectedSource
|
||||
{
|
||||
get { return _selectedSource; }
|
||||
set
|
||||
{
|
||||
if (_session.State == 4)
|
||||
{
|
||||
_session.CurrentSource.Close();
|
||||
}
|
||||
_selectedSource = value;
|
||||
RaisePropertyChanged(() => SelectedSource);
|
||||
if (_selectedSource != null)
|
||||
{
|
||||
_selectedSource.Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int State { get { return _session.State; } }
|
||||
|
||||
private IntPtr _winHandle;
|
||||
public IntPtr WindowHandle
|
||||
{
|
||||
get { return _winHandle; }
|
||||
set
|
||||
{
|
||||
_winHandle = value;
|
||||
if (value == IntPtr.Zero)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this for internal msg loop
|
||||
var rc = _session.Open();
|
||||
|
||||
// use this to hook into current app loop
|
||||
//var rc = _session.Open(new WpfMessageLoopHook(value));
|
||||
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
ReloadSourcesCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowUI
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ICommand _showDriverCommand;
|
||||
public ICommand ShowDriverCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showDriverCommand ?? (_showDriverCommand = new RelayCommand(() =>
|
||||
{
|
||||
if (_session.State == 4)
|
||||
{
|
||||
var rc = _session.CurrentSource.Enable(SourceEnableMode.ShowUIOnly, false, WindowHandle);
|
||||
}
|
||||
}, () =>
|
||||
{
|
||||
return _session.State == 4 && _session.CurrentSource.Capabilities.CapEnableDSUIOnly.GetCurrent() == BoolType.True;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _captureCommand;
|
||||
public ICommand CaptureCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _captureCommand ?? (_captureCommand = new RelayCommand(() =>
|
||||
{
|
||||
if (_session.State == 4)
|
||||
{
|
||||
//if (this.CurrentSource.ICapPixelType.Get().Contains(PixelType.BlackWhite))
|
||||
//{
|
||||
// this.CurrentSource.ICapPixelType.Set(PixelType.BlackWhite);
|
||||
//}
|
||||
|
||||
//if (this.CurrentSource.ICapXferMech.Get().Contains(XferMech.File))
|
||||
//{
|
||||
// this.CurrentSource.ICapXferMech.Set(XferMech.File);
|
||||
//}
|
||||
|
||||
var rc = _session.CurrentSource.Enable(
|
||||
ShowUI ? SourceEnableMode.ShowUI : SourceEnableMode.NoUI, false, WindowHandle);
|
||||
}
|
||||
}, () =>
|
||||
{
|
||||
return _session.State == 4;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//private ICommand _saveCommand;
|
||||
//public ICommand SaveCommand
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return _saveCommand ?? (_saveCommand = new RelayCommand(() =>
|
||||
// {
|
||||
// Messenger.Default.Send(new ChooseFileMessage(this, files =>
|
||||
// {
|
||||
// var tiffPath = files.FirstOrDefault();
|
||||
|
||||
// var srcFiles = CapturedImages.Select(ci=>ci.)
|
||||
// })
|
||||
// {
|
||||
// Caption = "Save to File",
|
||||
// Filters = "Tiff files|*.tif,*.tiff"
|
||||
// });
|
||||
// }, () =>
|
||||
// {
|
||||
// return CapturedImages.Count > 0;
|
||||
// }));
|
||||
// }
|
||||
//}
|
||||
|
||||
private ICommand _clearCommand;
|
||||
public ICommand ClearCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _clearCommand ?? (_clearCommand = new RelayCommand(() =>
|
||||
{
|
||||
CapturedImages.Clear();
|
||||
}, () =>
|
||||
{
|
||||
return CapturedImages.Count > 0;
|
||||
}));
|
||||
}
|
||||
}
|
||||
private ICommand _reloadSrc;
|
||||
public ICommand ReloadSourcesCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reloadSrc ?? (_reloadSrc = new RelayCommand(() =>
|
||||
{
|
||||
DataSources.Clear();
|
||||
foreach (var s in _session.Select(s => new DataSourceVM { DS = s }))
|
||||
{
|
||||
DataSources.Add(s);
|
||||
}
|
||||
}, () =>
|
||||
{
|
||||
return _session.State > 2;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the captured images.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The captured images.
|
||||
/// </value>
|
||||
public ObservableCollection<ImageSource> CapturedImages { get; private set; }
|
||||
|
||||
public double MinThumbnailSize { get { return 50; } }
|
||||
public double MaxThumbnailSize { get { return 300; } }
|
||||
|
||||
private double _thumbSize = 150;
|
||||
public double ThumbnailSize
|
||||
{
|
||||
get { return _thumbSize; }
|
||||
set
|
||||
{
|
||||
if (value > MaxThumbnailSize) { value = MaxThumbnailSize; }
|
||||
else if (value < MinThumbnailSize) { value = MinThumbnailSize; }
|
||||
_thumbSize = value;
|
||||
RaisePropertyChanged(() => ThumbnailSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
void _session_SourceDisabled(object sender, EventArgs e)
|
||||
{
|
||||
Messenger.Default.Send(new RefreshCommandsMessage());
|
||||
}
|
||||
|
||||
void _session_TransferError(object sender, TransferErrorEventArgs e)
|
||||
{
|
||||
App.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (e.Exception != null)
|
||||
{
|
||||
Messenger.Default.Send(new MessageBoxMessage(e.Exception.Message, null)
|
||||
{
|
||||
Caption = "Transfer Error Exception",
|
||||
Icon = System.Windows.MessageBoxImage.Error,
|
||||
Button = System.Windows.MessageBoxButton.OK
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.Default.Send(new MessageBoxMessage(string.Format("Return Code: {0}\nCondition Code: {1}", e.ReturnCode, e.SourceStatus.ConditionCode), null)
|
||||
{
|
||||
Caption = "Transfer Error",
|
||||
Icon = System.Windows.MessageBoxImage.Error,
|
||||
Button = System.Windows.MessageBoxButton.OK
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void _session_TransferReady(object sender, TransferReadyEventArgs e)
|
||||
{
|
||||
var mech = _session.CurrentSource.Capabilities.ICapXferMech.GetCurrent();
|
||||
if (mech == XferMech.File)
|
||||
{
|
||||
var formats = _session.CurrentSource.Capabilities.ICapImageFileFormat.GetValues();
|
||||
var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;
|
||||
|
||||
var fileSetup = new TWSetupFileXfer
|
||||
{
|
||||
Format = wantFormat,
|
||||
FileName = GetUniqueName(Path.GetTempPath(), "twain-test", "." + wantFormat)
|
||||
};
|
||||
var rc = _session.CurrentSource.DGControl.SetupFileXfer.Set(fileSetup);
|
||||
}
|
||||
else if (mech == XferMech.Memory)
|
||||
{
|
||||
// ?
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
string GetUniqueName(string dir, string name, string ext)
|
||||
{
|
||||
var filePath = Path.Combine(dir, name + ext);
|
||||
int next = 1;
|
||||
while (File.Exists(filePath))
|
||||
{
|
||||
filePath = Path.Combine(dir, string.Format("{0} ({1}){2}", name, next++, ext));
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
void _session_DataTransferred(object sender, DataTransferredEventArgs e)
|
||||
{
|
||||
ImageSource img = GenerateThumbnail(e);
|
||||
if (img != null)
|
||||
{
|
||||
App.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
CapturedImages.Add(img);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImageSource GenerateThumbnail(DataTransferredEventArgs e)
|
||||
{
|
||||
BitmapSource img = null;
|
||||
|
||||
switch (e.TransferType)
|
||||
{
|
||||
case XferMech.Native:
|
||||
using (var stream = e.GetNativeImageStream())
|
||||
{
|
||||
if (stream != null)
|
||||
{
|
||||
img = stream.ConvertToWpfBitmap(300, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case XferMech.File:
|
||||
img = new BitmapImage(new Uri(e.FileDataPath));
|
||||
if (img.CanFreeze)
|
||||
{
|
||||
img.Freeze();
|
||||
}
|
||||
break;
|
||||
case XferMech.Memory:
|
||||
// TODO: build current image from multiple data-xferred event
|
||||
break;
|
||||
}
|
||||
|
||||
//if (img != null)
|
||||
//{
|
||||
// // from http://stackoverflow.com/questions/18189501/create-thumbnail-image-directly-from-header-less-image-byte-array
|
||||
// var scale = MaxThumbnailSize / img.PixelWidth;
|
||||
// var transform = new ScaleTransform(scale, scale);
|
||||
// var thumbnail = new TransformedBitmap(img, transform);
|
||||
// img = new WriteableBitmap(new TransformedBitmap(img, transform));
|
||||
// img.Freeze();
|
||||
//}
|
||||
return img;
|
||||
}
|
||||
|
||||
internal void CloseDown()
|
||||
{
|
||||
if (_session.State == 4)
|
||||
{
|
||||
_session.CurrentSource.Close();
|
||||
}
|
||||
_session.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" /></startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="GalaSoft.MvvmLight" publicKeyToken="0e453835af4ee6ce" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.3.0.19038" newVersion="5.3.0.19038" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommonServiceLocator" version="1.3" targetFramework="net4-client" />
|
||||
<package id="Microsoft.WindowsAPICodePack-Core" version="1.1.0.2" targetFramework="net4-client" />
|
||||
<package id="Microsoft.WindowsAPICodePack-Shell" version="1.1.0.0" targetFramework="net4-client" />
|
||||
<package id="ModernWpf" version="2.0.0-alpha94" targetFramework="net40-client" />
|
||||
<package id="ModernWpf.Core" version="2.0.0-alpha96" targetFramework="net40-client" />
|
||||
<package id="MvvmLightLibs" version="5.3.0.0" targetFramework="net40-client" />
|
||||
</packages>
|
Binary file not shown.
Before Width: | Height: | Size: 54 KiB |
@ -1,19 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
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")]
|
@ -1,63 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
<?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>
|
@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// 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", "14.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
<?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>
|
@ -1,96 +0,0 @@
|
||||
<?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>x64</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>
|
329
samples/Sample.Winform/TestForm.Designer.cs
generated
329
samples/Sample.Winform/TestForm.Designer.cs
generated
@ -1,329 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,422 +0,0 @@
|
||||
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) =>
|
||||
{
|
||||
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
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v2.0.50727" sku="Client"/></startup></configuration>
|
Binary file not shown.
Before Width: | Height: | Size: 54 KiB |
Loading…
Reference in New Issue
Block a user