Sample improvements

This commit is contained in:
Ben Olden-Cooligan 2019-03-16 10:25:47 -04:00
parent e7f83fc371
commit 2bbfc3b70e
4 changed files with 32 additions and 0 deletions

View File

@ -19,6 +19,7 @@ namespace NAPS2.Sdk.Samples
// To save memory, we can store scanned images on disk after initial processing.
// This will put files in the system temp folder by default, which can be
// overriden by changing FileStorageManager.Current.
// TODO: Probably this should go on StorageManager? It's weird to have to remember what's where
ScannedImage.ConfigureBackingStorage<IFileStorage>();
IScanDriver driver = new WiaScanDriver();

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NAPS2.Images;
using NAPS2.Scan;
using NAPS2.Scan.Wia;
namespace NAPS2.Sdk.Samples
{
public class HelloWorldSample
{
public static async Task Run()
{
// This is the absolute bare bones example of scanning.
// See the other samples for more description and functionality.
IScanDriver driver = new WiaScanDriver();
ScannedImageSource imageSource = driver.Scan(new ScanProfile(), new ScanParams());
await imageSource.ForEach(scannedImage =>
{
using (scannedImage)
{
Console.WriteLine("Scanned a page!");
}
});
}
}
}

View File

@ -48,6 +48,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="FileStorageSample.cs" />
<Compile Include="HelloWorldSample.cs" />
<Compile Include="ScanToBitmapSample.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@ -55,6 +55,7 @@ namespace NAPS2.Sdk.Samples
// ForEach allows you to asynchronously process images as they arrive.
await imageSource.ForEach(async scannedImage =>
{
// Make sure ScannedImage and rendered images are disposed after use
using (scannedImage)
using (Bitmap bitmap = await renderer.Render(scannedImage))
{