Add NAPS2.Sdk.Samples project

This commit is contained in:
Ben Olden-Cooligan 2018-11-30 14:10:30 -05:00
parent be42bfee7c
commit 7428558ed2
5 changed files with 205 additions and 0 deletions

33
NAPS2.Sdk.Samples/.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.sln.docstates
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
*.vssscc
$tf*/
publish/
bin/
temp/
*.credentials.json

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{1165EE3A-5EE1-462B-8D9F-975D66710F1A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NAPS2.Sdk.Samples</RootNamespace>
<AssemblyName>NAPS2.Sdk.Samples</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ScanToBitmapSample.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NAPS2.Sdk\NAPS2.Sdk.csproj">
<Project>{968378fa-a649-4058-a928-1fcd97b23070}</Project>
<Name>NAPS2.Sdk</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
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("NAPS2.Sdk.Samples")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NAPS2.Sdk.Samples")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("1165ee3a-5ee1-462b-8d9f-975d66710f1a")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using NAPS2.Images;
using NAPS2.Images.Storage;
using NAPS2.Scan;
using NAPS2.Scan.Wia;
namespace NAPS2.Sdk.Samples
{
public class ScanToBitmapSample
{
public static async IAsyncEnumerable<Bitmap> Run()
{
// TODO: Configure image factory.
// We configure scanned images to be stored in GDI+ format.
// This uses System.Drawing.Bitmap internally.
ScannedImage.ConfigureBackingStorage<GdiImage>();
// TODO: Put this in another sample.
// Alternatively, we could store images on disk to save memory.
// This would put files in the system temp folder by default,
// which can be overriden by changing FileStorageManager.Current.
// ScannedImage.ConfigureBackingStorage<IFileStorage>();
// To select a device and scan, you need a driver.
// Windows supports Wia and Twain. Linux supports Sane. Mac supports Twain.
// You can use the IScanDriver.IsSupported property to help choose if needed.
IScanDriver driver = new WiaScanDriver();
// For the purpose of this sample, we arbitrarily pick the first scanning device.
// You probably want to let the user select one. Use IScanDriver.PromptForDevice()
// to show a device prompt. This may use Windows Forms for some drivers.
ScanDevice device = driver.GetDeviceList().First();
// Configure basic scanning options (these are usually presented to the user)
driver.ScanProfile = new ScanProfile
{
Device = device,
Resolution = ScanDpi.Dpi300
};
// Configure meta scanning options
driver.ScanParams = new ScanParams
{
NoUI = true
};
// This starts the scan and immediately returns with an object that asynchronously
// receives the results of the scan.
ScannedImageSource imageSource = driver.Scan();
// To change a ScannedImage object into a Bitmap object we need a renderer.
// Since our backing storage already uses a Bitmap, this is a fairly trivial operation.
// However, in other situations this abstracts away additional I/O or transforms.
BitmapRenderer renderer = new BitmapRenderer();
// Using the new C# 8.0 language features and IAsyncEnumerable allows this to be
// done cleanly and fully asynchronously.
await foreach (ScannedImage image in imageSource.AsAsyncEnumerable())
{
Bitmap bitmap = await renderer.Render(image);
yield return bitmap;
}
}
}
}

View File

@ -39,6 +39,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NAPS2.Sdk.NativeWia", "NAPS
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "NAPS2.Setup", "NAPS2.Setup\NAPS2.Setup.csproj", "{C12ACB2C-184F-4CBD-9FBC-CE1331CF592E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NAPS2.Sdk.Samples", "NAPS2.Sdk.Samples\NAPS2.Sdk.Samples.csproj", "{1165EE3A-5EE1-462B-8D9F-975D66710F1A}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
NAPS2.Setup\NAPS2.Setup.projitems*{c12acb2c-184f-4cbd-9fbc-ce1331cf592e}*SharedItemsImports = 13
@ -156,6 +158,16 @@ Global
{C12ACB2C-184F-4CBD-9FBC-CE1331CF592E}.InstallerMSI|x86.ActiveCfg = Debug|Any CPU
{C12ACB2C-184F-4CBD-9FBC-CE1331CF592E}.Standalone|x86.ActiveCfg = Debug|Any CPU
{C12ACB2C-184F-4CBD-9FBC-CE1331CF592E}.Standalone|x86.Build.0 = Debug|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.Debug|x86.ActiveCfg = Debug|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.Debug|x86.Build.0 = Debug|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.DebugLang|x86.ActiveCfg = Debug|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.DebugLang|x86.Build.0 = Debug|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.InstallerEXE|x86.ActiveCfg = Release|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.InstallerEXE|x86.Build.0 = Release|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.InstallerMSI|x86.ActiveCfg = Release|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.InstallerMSI|x86.Build.0 = Release|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.Standalone|x86.ActiveCfg = Release|Any CPU
{1165EE3A-5EE1-462B-8D9F-975D66710F1A}.Standalone|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE