The LEADTOOLS WIA driver is available in LEADTOOLS version 16 or higher.
This tutorial is to provides you with a quick and easy way to generate a WIA program. For more in depth WIA programming, refer to the WIA demo.
Take the following steps to create and run a program that implement LEADTOOLS WIA features.
Start Microsoft Visual Studio
Select the File->New menu option, click the "Project" menu.
From "Project Types" select "Other Languages" to expand it, then select "Visual C++" to expand it, then select "MFC". From the right window select "MFC Application".
In the Project Name dialog box, enter "WiaStillImageTutor".
In the Location dialog box, use the "Examples\Scanning\ClassLibrary" directory of your LEAD installation. For example, if you installed LEADTOOLS in C:\LEADTOOLS22\
, enter C:\LEADTOOLS22\Examples\Scanning\ClassLibrary
, then Click OK. Then click "Next".
Choose "Dialog based" and click "Finish".
Click on the "Solution Explorer" tab, and then click on the "WiaStillImageTutor" project to expand it. Click on the Header files, then Open "WiaStillImageTutor.h".
Add the following line immediately before the class CWiaStillImageTutorApp declaration, (keep in mind, you may have to change the path to where the header files reside):
#include "..\..\..\..\include\ClassLib\ltwrappr.h"
Click on the "Class View" tab.
Click to open the "WiaStillImageTutor" classes branch.
Click "CWiaStillImageTutorApp", and then double click the CWiaStillImageTutorApp(void) constructor.
Add the following lines after //TODO: add construction code here
:
LBase::LoadLibraries(LT_ALL_LEADLIB);
L_TCHAR * pszLicenseFile = L"Replace this with the path to the LEADTOOLS license file";
L_TCHAR * pszDeveloperKey = L"Replace this with your developer key";
LSettings::SetLicenseFile(pszLicenseFile, pszDeveloperKey);
Create a new file called Imports.cpp in place it beside your project files.
In the Project Workspace, click the Solution Explorer tab.
Double-click the WiaStillImageTutor folder to open it.
Select C++ File (.cpp) from the right window.
In the name text box, specify Imports.cpp
Click the Add button.
Double-click the imports.cpp in the solution Explorer and add the following lines:
#include "StdAfx.h"
#if defined(WIN64)
#pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltwvc_x.lib")
#else
#pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc_u.lib")
#endif // #if defined(WIN64)
Click on the "Class View" tab.
Double-click the "WiaStillImageTutor" folder to open it.
Right click "CWiaStillImageTutorDlg" and select "Add Variable..."
For Variable Type enter LWia
, and for Variable Declaration put m_MyWia
. Leave Access as "Public" and click OK.
Click to open the CWiaStillImageTutorDlg
branch. Double click the OnInitDialog()
function and add the following code after line:
// TODO: Add extra initialization here
m_MyWia.InitSession(WiaVersion1);
Right click the CWiaStillImageTutorDlg branch, and choose "Properties".
From the "Properties" window toolbar, click on the Messages icon. Then click on the empty area beside the item "WM_DESTROY" and choose OnDestroy
.
Add the following code after the opening bracket {:
m_MyWia.EndSession();
LBase::UnloadLibraries(LT_ALL_LEADLIB);
Click on the "Solution Explorer" tab.
Double-click the "WiaStillImageTutor" folder to open it.
Double-click the "Resource Files" folder to open it. Then double click "WiaStillImageTutor.rc" file to open it, then double click "Dialog", and then double click "IDD_WIASTILLIMAGETUTOR_DIALOG"
Now, drag and drop 4 buttons and 1 custom control (to render the video preview in it), and change their properties as follows:
Button | ID | Caption |
---|---|---|
Button1 | IDC_SELECT_VIDEO_SRC Select | Video Source |
Button2 | IDC_START_VIDEO_PREVIEW | Start Video Preview |
Button3 | IDC_ACQUIRE_STILL_IMAGE | Acquire Still Image |
Button4 | IDC_STOP_VIDEO_PREVIEW | Stop Video Preview |
CustomControl1 | IDC_PREVIEW_CONTROL |
From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_WIASTILLIMAGETUTOR_DIALOG".
Double click on "Select Video Source" button, and add the following code:
m_MyWia.SelectDeviceDlg(WiaDeviceTypeStreamingVideo, L_WIA_SELECT_DEVICE_NODEFAULT);
From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_WIASTILLIMAGETUTOR_DIALOG".
Double click on "Start Video Preview" button, and add the following code:
m_MyWia.SetWindow(GetDlgItem(IDC_PREVIEW_CONTROL)->m_hWnd);
m_MyWia.StartVideoPreview(FALSE);
From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_WIASTILLIMAGETUTOR_DIALOG".
Double click on "Acquire Still Image" button, and add the following code:
L_TCHAR szTakenImageFileName[MAX_PATH] = TEXT("");
L_SIZE_T uLength = MAX_PATH;
L_INT nRet = WIA_SUCCESS;
if(m_MyWia.IsVideoPreviewAvailable())
{
nRet = m_MyWia.AcquireImageFromVideo(szTakenImageFileName, &uLength);
if(nRet == WIA_SUCCESS)
{
MessageBox(szTakenImageFileName, TEXT("Saved file path..."), MB_OK);
}
}
From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_WIASTILLIMAGETUTOR_DIALOG".
Double click on "Stop Video Preview" button, and add the following code:
if(m_MyWia.IsVideoPreviewAvailable())
{
m_MyWia.EndVideoPreview();
}
Compile and test the program.