Acquire Images Using Fast TWAIN Features

Note: The purpose of this TWAIN tutorial is to provide you a quick and easy way to generate a TWAIN program. For more in-depth TWAIN programming, refer to the TWAIN demo.

To acquire images using the LEADTOOLS Fast TWAIN features:

Take the following steps to start a new project:

  1. Run Microsoft Visual Studio 2005, select the File -> New -> Project menu option, and do the following:

    1. Select the Other Languages -> Visual C++ -> MFC.

    2. Select MFC Application as the project type.

    3. In the Project name text box, specify tutor.

    4. In the Location text box, specify the path of the project.

    5. Click the OK button, then click the Next button

  2. In the next dialog box, do the following:

    1. Select Dialog-based.

    2. Ensure Use MFC in shared DLL is selected

    3. Click the Finish button.

  3. Add #include statements to your program so you can access the LEAD Twain DLL functions:

    1. In the Project Workspace, click the FileView tab.

    2. Double-click the tutor files folder to open it.

    3. Double-click the Header Files folder to open it.

    4. Double-click the StdAfx.h file to edit it.

    5. Add the following lines to the end of the file (keep in mind, you may have to change the path to where the DLLs reside):

      \#include "..\..\..\include\l_bitmap.h" 
      \#include "..\..\..\include\lttwn.h" 

  4. Add the LEAD Twain LIB file to your program. Open tutorDlg.cpp, and add the following line after the #include statements:

    #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Lttwn_u.lib") 

  5. Add a HTWAINSESSION member to the class and set it to NULL in the constructor.

    1. Open tutorDlg.h file and add the following line after HICON m_hIcon;

      HTWAINSESSION m_hSession; 

    2. Open tutorDlg.cpp file and add the following line inside CtutorDlg::CtutorDlg

       m_hSession = NULL; 

  6. Go to the Solution Explorer and click the Resource Files, and double-click the .rc file. Double-click Dialog and double-click IDD_TUTOR_DIALOG to open the application's dialog box.

  7. Add 1 check box. To do this, select the check box control on the Controls toolbar. Then, click and drag to position the button on the dialog box. Then double-click the check box to change its properties. Set the properties as follows:

    ID Caption
    IDC_USEBUFFERSIZE Use Buffer Size
  8. Add two Radio buttons in addition to the check box.

    ID Caption
    IDC_NATIVE Native Mode
    IDC_MEMORY Memory Mode
  9. Add the following button:

    ID Caption
    IDC_ACQUIRE Fast Acquire
  10. Add the following two edit boxes and name them as follows:

    ID
    IDC_BUFFERSIZE
    IDC_FILENAME
  11. Add the following code to the end of OnInitDialog before the return statement:

    APPLICATIONDATA AppData;   
    AppData.uStructSize = sizeof(APPLICATIONDATA);   
    AppData.hWnd = GetSafeHwnd(); // Window handle of an application, may not be NULL   
    lstrcpy (AppData.szManufacturerName, TEXT("LEAD Technologies, Inc.")); // Application manufacturer name   
    lstrcpy (AppData.szAppProductFamily, TEXT("LEAD Test Applications")); // Application product family   
    lstrcpy (AppData.szVersionInfo, TEXT("Version 14.0")); // Application version info   
    lstrcpy (AppData.szAppName, TEXT("TWAIN Utility Application")); // Application Name   
    // initialize the twain session to use other lead twain functions   
    L_INT nRet = L_TwainInitSession (&m_hSession, &AppData);   
    if (nRet != SUCCESS)   
       return FALSE; 

  12. To end the TWAIN session and free memory allocated by the TWAIN DLL, add the following code in the WM_DESTROY of the CTutorDlg. Take the following steps:

    1. Double-click the dialog IDD_TUTOR_DIALOG, and then go to View -> Properties Window, and then press the Messages button.

    2. Select WM_DESTROY, and then add OnDestroy from the list box.

      if (m_hSession)   
         L_TwainEndSession (&m_hSession); 

  13. Add the following member variables for the following controls. To do so, go to Class View from Solution Explorer, select CtutorDlg, and then go to Project -> Add Variable menu, then do the following:

    1. Check Control variable check box.

    2. Select each of the following controls and add the corresponding member variable by pressing the Finish variable button.

    ID Member Variable Type Category
    IDC_USEBUFFERSIZE m_bUseBufferSize BOOL Value
    IDC_BUFFERSIZE m_nBufferSize int Value
    IDC_FILENAME m_csFileName CString Value
  14. Double-click the dialog IDD_TUTOR_DIALOG, and then double-click the Fast Acquire button to add the OnBnClickedAcquire handler function. Add the following code:

    void CTutorDlg::OnBnClickedAcquire () 
    { 
       UpdateData(); 
       L_INT  nFormat; 
       L_UINT uTransferMode; 
       BOOL bMemory = IsDlgButtonChecked(IDC_MEMORY); 
       if (bMemory) 
       { 
          uTransferMode = LTWAIN_BUFFER_MODE; 
          nFormat = FILE_CCITT_GROUP4; 
       } 
       else 
       { 
          uTransferMode = LTWAIN_NATIVE_MODE; 
          nFormat = FILE_TIF; 
       } 
       L_INT nRet = L_TwainAcquireMulti (m_hSession, 
       (L_TCHAR *)(LPCTSTR)m_csFileName, 
       LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE, 
       uTransferMode, 
       nFormat, 
       1, 
       TRUE, 
       m_nBufferSize, 
       !m_bUseBufferSize , NULL, NULL); 
       if (nRet == 1) 
          AfxMessageBox(TEXT("Fast Scanning process done successfully...")); 
       else 
       { 
          CString csError; 
          csError.Format(TEXT("AcquireMulti failed, Error = %d\n"), nRet); 
          AfxMessageBox(csError); 
       } 
    } 

  15. Compile and run your program to test it.

  16. Enter a value (for example, 1000) for the buffer size and a file name (include the full path) for the scanned image.>

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS TWAIN C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.