X

Capture Photos and Images with WIA

WIA stands for Windows Image Acquisition and has been introduced since Windows ME. Born to address the many problems in using the old protocol TWAIN, today became the basis for all capture devices. The focus of this article is to explain how to use our applications in C/C++, as for example in XXXXX (software for inventory) that uses this technology to capture images to be included in the database.

First of all blocks so that the program does not have to create a worker thread that does all the work and see when he’s finished with a semaphore:

CWinThread* pThread = AfxBeginThread(AcquireThreadProc, this);
AfxGetMainWnd()->EnableWindow(FALSE);
while (MsgWaitForMultipleObjects(1, &pThread->m_hThread,
     FALSE, INFINITE, QS_ALLINPUT, QS_ALLPOSTMESSAGE) == WAIT_OBJECT_0 + 1)
{
    MSG msg;
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
           TranslateMessage(&msg);
           DispatchMessage(&msg);
    }
}

Here is the code to wait until the end of the acquisition, while we can see how it should be implemented as AcquireThreadProc thread initialized, a simple callback function must initialize the static object COM (Component Object Model) IWiaDevMgr this:

CoInitialize(NULL);
CComPtr pDev;
HRESULT hr = pDev.CoCreateInstance(CLSID_WiaDevMgr);
if (hr != S_OK)
{
    CoUninitialize();
    return 1;
}

Last thing to do and also the simplest method is to call the object GetImageDlg IWiaDevMgr created before:

GUID guidFormat = GUID_NULL;
HRESUT hr = pDev->GetImageDlg(((CWnd*)pParam)->m_hWnd,
       StiDeviceTypeDefault, WIA_DEVICE_DIALOG_SINGLE_IMAGE, WIA_INTENT_NONE,
       NULL, szBuffer, &guidFormat);
if (FAILED(hr))
{
    CoUninitialize();
    return 1;
}

With this method we are done, but if we go deeper in detail and manage the acquisition, there are many other methods of serving more than atro to customize the various stages of this procedure. I remember that we can capture pictures and images from scanners, cameras and all that hardware is compatible with the technology WIA (Windows Image Acquisition).
Our latest application exploits this technology to capture images and insert them into the database of customers, suppliers, inventory items, and other employees and can be found on our site.

Tags: VC/C++
giampy107:
X

Cookies Policy

We use cookies to personalize content and ads, provide social media features and analyze our traffic. We also share information about your use of our site with our web analytics, advertising and social media partners who may combine it with other information you have provided to them or that they have collected based on your use of theirs. services.

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings