Loading...

Twain Auto Size

Support for GdPicture Light Imaging Toolkit and GdPicture Pro Imaging ActiveX/SDK.

Twain Auto Size

Postby nschafer » Thu Jun 04, 2009 12:06 am

Hello Loic,

I've read through several posts in the forums trying to resolve my issues with auto page size when scanning. So far nothing is working quite right.
I am using an Epson GT-S50 Scanner on a computer running Windows XP Pro SP2. The Scanner is using a TWAIN driver v3.61A. I am running the most current version of GdPicturePro (5.99011141) downloaded today.

Several features available via the UI report that they are not available when trying to use them without the UI. For Example:

TwainIsAutoSizeAvailable returns False, althougth there is an Auto-Size option in the UI that works very well.

TwainIsAutomaticBorderDetectionAvailable returns False

TwainIsAutomaticDiscardBlankPagesAvailable returns false, although there is an option for that in the UI

So far my main problem is with the Auto-Size as the subject of this topic implies.

I am working with your sample app: twain_sample from the vb.net sample folder and modifying the code for the Demo 1 button.

Adding the code: Call Imaging1.CropWhiteBorders() removes cleans up my image size vertically, but not horizontally. There is a gray border on both sides of the card. Using CropBlackBorders() and CropBordersEX() do not seem to allow me to remove they gray border.

My current code is as follows:
Code: Select all
Dim nImageID As Integer
      
If Imaging1.TwainOpenDefaultSource() Then
         
            InitScanConfig()
         
            Imaging1.TwainSetCurrentResolution(200)
            Imaging1.TwainSetCurrentPixelType(GdPicturePro5.TwainPixelType.TWPT_GRAY) ' Grayscale
            Imaging1.TwainSetCurrentBitDepth(8)
            Imaging1.TwainSetPaperSize(GdPicturePro5.TwainPaperSize.USLETTER)


            nImageID = Imaging1.CreateImageFromTwain(Me.Handle.ToInt32)
            If nImageID <> 0 Then
                Call Imaging1.CropBlackBorders(5, 0)
                Call Imaging1.CropWhiteBorders(5, 0)
                Call Imaging1.CropBordersEX(5)
                Call ApplyImageFilters(nImageID)
                If chkPreview.CheckState = 1 Then Call DisplayNativeImage()
                Call Imaging1.SaveAsJPEG(My.Application.Info.DirectoryPath & "\acquire.jpg", 90)
                Call Imaging1.CloseImage(nImageID)
            End If
         
            Call Imaging1.TwainCloseSource()
                MsgBox("Done !")
Else
                MsgBox("can't open default source, twain state is: " & Trim(Str(Imaging1.TwainGetState)))
End If

Thanks for any help with this issue.

Neal.
nschafer
 
Posts: 25
Joined: Tue Oct 30, 2007 10:05 pm

Re: Twain Auto Size

Postby nschafer » Fri Jun 05, 2009 8:28 pm

I've been working on this further and have come up with the following: (Converted to C# previous in VB)

Code: Select all
int nImageID;
int nImageCount = 0;
if (Imaging1.TwainOpenDefaultSource())
{
    InitScanConfig();
    Imaging1.TwainSetAutoFeed(true);
    Imaging1.TwainSetAutoScan(true);
    Imaging1.TwainSetCurrentResolution(200);
    Imaging1.TwainSetCurrentPixelType(GdPicturePro5S.TwainPixelType.TWPT_GRAY); //Grayscale
    Imaging1.TwainSetCurrentBitDepth(8);
    Imaging1.TwainSetPaperSize(GdPicturePro5S.TwainPaperSize.USLETTER);
    while (Imaging1.CreateImageFromTwain((int)this.Handle) != 0)
    {
        nImageID = Imaging1.GetNativeImage();
        Imaging1.CropBorders();
        Imaging1.CropBorders();
        if (!Imaging1.IsBlank())
        {
            nImageCount++;
            Imaging1.SaveAsJPEG(AppDomain.CurrentDomain.BaseDirectory + "\\acquire" + nImageCount.ToString() + ".jpg", 90);
        }
        Imaging1.CloseImage(nImageID);
    }
    Imaging1.TwainCloseSource();
    MessageBox.Show("Done !");
}
else
{
    MessageBox.Show("can't open default source, twain state is: " + Imaging1.TwainGetState().ToString());
}



By running the cropborders() twice it seems to get rid of the borders around the card or other smaller documents. But it also removes some of the content of a letter size page. To be more precise it is pulling to border in from the edge of the paper to the area where there is text on the page, but it seems to go a little too far and remove some actual text as well.

Any thoughts?


P.S. The editor in the forums jumps like crazy when it has to scroll with IE8. Very difficult to enter the message.
nschafer
 
Posts: 25
Joined: Tue Oct 30, 2007 10:05 pm

Re: Twain Auto Size

Postby jesusahmed » Thu Jul 23, 2009 8:00 pm

Hi

Have you been able to solve the automatic detection of page grayscale?

Thanks
jesusahmed
 
Posts: 3
Joined: Thu Jul 09, 2009 7:58 am

Re: Twain Auto Size

Postby nschafer » Thu Jul 23, 2009 8:51 pm

Not 100%. What I've come up with seems to work well except on full page 8.5 x 11 paper. on full page documents it tends to crop off too much, so what I've done is create a combo-box with various sizes, which defaults to full page as that is the most common at my office. If any other page size is used then I crop the borders and it seems to work well enough, but the user still has to select a page size one way or another so it is not Auto-Size.
Here's the code I'm using, hope it helps:

Code: Select all
            int nImageID;
            if (Imaging1.TwainOpenDefaultSource())
            {
                InitScanConfig();
                Imaging1.TwainSetAutoFeed(true);
                Imaging1.TwainSetAutoScan(true);
                Imaging1.TwainSetCurrentResolution(200);
                Imaging1.TwainSetCurrentPixelType(GdPicturePro5.TwainPixelType.TWPT_GRAY); // Grayscale
                Imaging1.TwainSetCurrentBitDepth(8);
                Imaging1.TwainSetPaperSize(GdPicturePro5.TwainPaperSize.USLETTER);

                while (Imaging1.CreateImageFromTwain((int)this.Handle) != 0)
                {
                    // Imaging1.CropBorders();
                    if (!Imaging1.IsBlank(99))
                    {
                        nImageID = Imaging1.GetNativeImage();
                        Imaging1.CropBordersEX(98);
                        Imaging1.CropBordersEX(98);
                        if (cmbSize.SelectedIndex > 0)  // If not full sheet
                        {
                            Imaging1.CropBorders();
                        }
                        pageCount++;
                        currPage = pageCount;
                        SaveCurrentPage();
                        Imaging1.CloseImage(nImageID);
                    }
                }
                Imaging1.TwainCloseSource();


nschafer
 
Posts: 25
Joined: Tue Oct 30, 2007 10:05 pm


Return to GdPicture [Pro] ActiveX

Who is online

Users browsing this forum: Bing [Bot] and 1 guest