Saraff.Twain.DS.BitmapSource
2.1.6
dotnet add package Saraff.Twain.DS.BitmapSource --version 2.1.6
NuGet\Install-Package Saraff.Twain.DS.BitmapSource -Version 2.1.6
<PackageReference Include="Saraff.Twain.DS.BitmapSource" Version="2.1.6" />
<PackageVersion Include="Saraff.Twain.DS.BitmapSource" Version="2.1.6" />
<PackageReference Include="Saraff.Twain.DS.BitmapSource" />
paket add Saraff.Twain.DS.BitmapSource --version 2.1.6
#r "nuget: Saraff.Twain.DS.BitmapSource, 2.1.6"
#:package Saraff.Twain.DS.BitmapSource@2.1.6
#addin nuget:?package=Saraff.Twain.DS.BitmapSource&version=2.1.6
#tool nuget:?package=Saraff.Twain.DS.BitmapSource&version=2.1.6
Saraff.Twain.DS.BitmapSource
Simplifies the creation of a TWAIN Data Source that returns a bitmap.
Installation
PM> Install-Package Saraff.Twain.DS.BitmapSource
Compatibility
| Target | Supported |
|---|---|
net48 |
Yes |
net8.0-windows |
Yes |
net5.0-windows |
No, use net8.0-windows or net48 |
The package depends on Saraff.Twain.DS 1.2.0. Version 2.0.0 removes the net5.0-windows target and changes the assembly version to 2.0.0.0; rebuild consumers against the new package. Version 2.1.0 adds DAT_PALETTE8 support for 1, 4 and 8 bits per pixel.
Usage
Derive from BitmapDataSource and implement Acquire:
using System.Drawing;
using Saraff.Twain.DS.BitmapSource;
public sealed class SampleDataSource : BitmapDataSource {
protected override Bitmap Acquire() {
return new Bitmap("page.png");
}
}
A production Data Source also needs the usual TWAIN entry point and capability attributes provided by Saraff.Twain.DS. See the Saraff.Twain.DS wiki for a complete example.
To enable palette transfer, declare TwPixelType.Palette on the concrete Data Source and expose bit depths 1, 4 and 8 through ICAP_BITDEPTH. PixelTypeAttribute is not inherited, so the attribute must be applied to the concrete class:
[PixelType(TwPixelType.RGB, TwPixelType.Gray, TwPixelType.Palette)]
public sealed class SampleDataSource : BitmapDataSource {
public SampleDataSource() {
this[TwCap.BitDepth].Value=new ushort[] { 1,4,8,24 };
this[TwCap.BitDepth].Value=(DefaultValue<ushort>)8;
}
}
For 1-bit palette transfer, ICAP_BITORDER defaults to TWBO_MSBFIRST. To allow TWBO_LSBFIRST, add [LsbFirstSupported] to the concrete Data Source; the Source reverses the bits of each row during memory transfer.
Transfer behavior
- Native and memory transfers support
24bppRgb,48bppRgb, identity-grayscale8bppIndexedand palette1bppIndexed,4bppIndexed,8bppIndexed. - A grayscale request is converted to
8bppgrayscale; a palette request uses the requested bit depth (1, 4 or 8), preserving the source depth whenICAP_BITDEPTHis not a palette depth; other formats are converted to24bppRgb. - Memory transfer rows are padded with zero bytes to a 32-bit boundary as required by TWAIN 2.4;
BytesPerRowreports the padded row size, and palette images are transferred as packed indices within each row. The palette is reported byDG_IMAGE / DAT_PALETTE8forMSG_GETandMSG_GETDEFAULT;MSG_SETandMSG_RESETreturnTWRC_FAILURE/TWCC_BADPROTOCOL. TW_PALETTE8.NumColorsis 2, 16 or 256 depending on the palette bit depth.MSG_GETreturns the palette of the last acquired image and falls back to a depth-appropriate default palette before the first acquisition.- Native BMP transfers and file transfers embed the palette in the image format itself;
ICAP_BITORDERapplies only to 1-bit memory transfers. - Bilevel requests are transferred as
24bppRgb. - File transfer supports BMP, JPEG, PNG and TIFF. EXIF and multi-page TIFF are not supported.
- The memory transfer buffer is raised automatically when one image row does not fit into the default buffer.
ICAP_XFERCOUNT = -1is supported. The indeterminate series ends whenAcquire()returnsnullafter a transfer; the source callsEndOfXfers()and returns to state 5.- Image layout (crop/scale) and compression are not applied; the acquired bitmap is transferred as a whole and uncompressed.
- The image is released on end-of-transfer, reset and before the next acquisition.
Build
dotnet build Saraff.Twain.DS.BitmapSource.sln -c Release
dotnet test Saraff.Twain.DS.BitmapSource.sln -c Release
dotnet pack Saraff.Twain.DS.BitmapSource.csproj -c Release -o artifacts
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
| .NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- Saraff.Twain.DS (>= 1.3.3)
-
net8.0-windows7.0
- Saraff.Twain.DS (>= 1.3.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.