[Original] Scanning images from TWAIN equipment

xiaoxiao2021-03-06  78

1. Introduction to the Software Library of the TWAIN Data Source Management (DSM) industry standard for extracting images from still image devices. Most of the scanners and digital cameras provide a TWAIN driver, using a unified TWAIN interface, the application can easily get images from these devices. Second, using the steps on the Internet about TWAIN programming is very small, the code is difficult to find because I have to read the Twain Specification provided by www.twain.org carefully. Let's talk about the brief steps to get images using the TWAIN interface. There is a TWAIN_32.DLL in the Windows system. All TWAIN operations are implemented through this DLL exported DSM_ENTRY function (said that I personally think that the TWAIN interface is too bad, see the WIA of MS, logically very Clear). This function is declared as follows: TW_UINT16 FAR PASCAL DSM_Entry (pTW_IDENTITY pOrigin, // Source of message pTW_IDENTITY pDest, // Destination of message TW_UINT32 DG, // Data group ID: DG_xxxx TW_UINT16 DAT, // Data argument type: DAT_xxxx TW_UINT16 MSG, // Message ID: MSG_xxxx tw_memref pdata // Pointer to Data); 1. Open DSM (Data Source Manager: Data Source Manager) TWAIN is a data source management program, the application first uses the MSG_Opendsm message, open the data source manager . Here you need to specify a window handle, the application should process the TWAIN message (MSG_ProcessEvent) in the message loop of this window. 2. Select DS (Data Source: Data Source) Because there may be multiple TWAIN devices in a system, you must select a data source. Selecting data sources There are usually two ways: Select the default data source (MSG_GETDEFAULT) and display the Select Data Source dialog, by the user to select the data source (MSG_USERSELECT). 3. Open DS Use the MSG_OPENDS message to open the data source. 4. Set the parameter message to msg_set, set various parameters, such as acquisition mode, number of images, and the like. Some parameters are valid by device drive support. 5. Display the scan interface Use the MSG_EnableDS message to display the user interface (UI) provided by the device driver. 6. Get an image If the user selects what is scanned, you can get this event (MSG_xferReady) in the message loop of the window. At this point, the application can set the file name via the DAT_SETUPFILEXFER and then get the image to the file with DAT_IMAGEFILEXFER. 7. Turns off the scan interface to get the MSG_ClosedSreq or MSG_ClosedSok message in the message loop of the window, you can turn off the scan interface (msg_disableds). 8. Turn off the DS message for msg_closeds. 9. Turning off the data source message is MSG_ClosedSM. Third, the CTWAINHELPER assistant class For the convenience of use, I wrote a static TWAIN assistant CTWAINHELPER.

With the five functions of CTWAINHELPER, you can simply get images from the TWAIN device to the file. The method is as follows: Call CTWAINHELPER :: Initialize () determines if there is available device. In the Window Message loop, call CTWAINHELPER :: ProcessMessage () to process the TWAIN message. To get an image, call CTWAINHELPER :: getImage (). If the image is ready (such as the user determines the scan image), the window will receive a WM_COMMAND message, WPARAM is IDC_TWAINHELPER. At this time, the application can call CTWAINHELPER :: TransferImage () Get image to the file. Please refer to the sample code for details. CTWAINHELPER can be used in Visual C 6.x / 7.x project to support Unicode compilation. Because it is a static class, it is necessary to do a little bit of work if you have to rewrite it into C code. 4. Of course, the above is just a common step. In fact, applications can be customized all steps, such as direct scanning, or scanning images to memory without using TWAIN drivers, or scanning images to memory. For details, please refer to TWAIN Specification, the steps are similar, the messages and parameters are thousands of differences, take a closer look. It should be easy. If there is no TWAIN device to develop TWAIN program, you can download the TWAIN developers Toolkit to the TWAIN official website. There will be a virtual TWAIN device after installation. However, the application works normally in this virtual TWAIN device, does not mean you can use it in the actual TWAIN device, you need to pay attention. Previously, CTWAINHELPER had encountered such a situation in the virtual TWAIN device, it was clear, but the image was not scanned on my scanner. After the examination, it was found that the unsupported parameters were set. Finally, TWAIN is the abbreviation of technology, direct translation, "There is no technique that is not interested in the name", it is a name that makes people can't touch the mind. TWAIN Assistant: CTWAINHELPER (including sample code 35K) TWAIN official website: http://www.twain.org twain header file: http://www.twain.h TWAIN specification: http: // Www.twain.org/docs/spec1_9_197.pdf twain developers Toolkit: http://www.twain.org/devfiles/twainkit.exe

转载请注明原文地址:https://www.9cbs.com/read-94352.html

New Post(0)