Code: Select all
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
oGdPictureImaging = new GdPictureImaging();
//temp 30 day license
oGdPictureImaging.SetLicenseNumber("XXX");
//for (int nCpt = 1; nCpt < 3; nCpt++)
//{
// Console.WriteLine(oGdPictureImaging.TwainGetSourceName((IntPtr)null, nCpt));
// Console.ReadLine();
//}
oGdPictureImaging.TwainOpenSource((IntPtr)null,"Xerox DocuMate 252");
// Here we will scan in a 24bpp & 300 DPI from ADF into separate jpeg files
int nImageCount = 0;
int ImageID = 0;
//Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase transTemp6 = new Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase();
if (oGdPictureImaging.TwainOpenDefaultSource((IntPtr)null))
{
nImageCount = 0;
//InitScanConfig();
oGdPictureImaging.TwainSetHideUI(true);
oGdPictureImaging.TwainSetIndicators(true);
//if (System.Convert.ToDouble(chkAutoBrightness.CheckState) == 1)
//{
// oGdPictureImaging.TwainSetAutoBrightness(true);
//}
//else
//{
// oGdPictureImaging.TwainSetAutoBrightness(false);
// oGdPictureImaging.TwainSetBrightness(HBrightness.Value);
//}
//oGdPictureImaging.TwainSetContrast(HContrast.Value);
oGdPictureImaging.TwainEnableDuplex(false);
//End InitScanConfig();
oGdPictureImaging.TwainSetAutoFeed(true); // Set AutoFeed Enabled
oGdPictureImaging.TwainSetAutoScan(true); // To achieve the maximum scanning rate
oGdPictureImaging.TwainSetResolution(300);
oGdPictureImaging.TwainSetPixelType(TwainPixelType.TWPT_RGB); // RGB
oGdPictureImaging.TwainSetBitDepth(8); // 24 bpp
//Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase transTemp7 = new Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase();
do
{
ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage((IntPtr)null);
//Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase transTemp8 = new Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase();
if (ImageID != 0)
{
//ApplyImageFilters(ref ImageID);
//if (System.Convert.ToDouble(chkPreview.CheckState) == 1)
//{
// DisplayImage(ImageID);
//}
nImageCount = nImageCount + 1;
string transTemp0 = nImageCount.ToString();
//Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase transTemp9 = new Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase();
oGdPictureImaging.SaveAsJPEG(ImageID, @"C:\temp\image" + transTemp0.Trim() + ".jpg", 75);
oGdPictureImaging.ReleaseGdPictureImage(ImageID);
}
}
while (System.Convert.ToInt64(oGdPictureImaging.TwainGetState()) > System.Convert.ToInt64(TwainStatus.TWAIN_SOURCE_ENABLED));
oGdPictureImaging.TwainCloseSource();
//Interaction.MsgBox("Done !", (Microsoft.VisualBasic.MsgBoxStyle)(0), null);
}
else
{
//Interaction.MsgBox("can't open default source, twain state is: " + oGdPictureImaging.TwainGetState().ToString(), (Microsoft.VisualBasic.MsgBoxStyle)(0), null);
}