C# Sample: Acquire and save to BMP file

Top  Previous  Next

The following C# example is all that is required to do the following:

 

Check if TWAIN is installed.
Initialize the DTWAIN Dynamic Link Library.
Select a Source
Acquire a page using the Native transfer mode
Save page to a BMP file called "test.bmp"
Shut down any open TWAIN Source's and DTWAIN itself

___________________________________________________________

 

using DynaRithmic;

//....

[STAThread]

static void Main()

{

    int TwainOK = TwainAPI.DTWAIN_IsTwainAvailable()

    if ( TwainOK == 1 )

    {

         TwainAPI.DTWAIN_SysInitialize();

         TwainAPI.DTWAIN_TwainSave("-f test.bmp");

         TwainAPI.DTWAIN_SysDestroy();

    }

}

 

For C#, the DynaRithmic.TwainAPI class found in the file DTWAIN32.CS is a class wrapper for the DTWAIN functions.  Note that it is as simple as calling five DTWAIN functions to get the job done.