[Crystal Studio Web] [Delphi] Controls the scanner in Delphi ---- When using the Delphi development information management system, the image is often handled, which is also an inevitable trend of the development of the information management system. How to get the desired image information through the scanner in Delphi? There are three basic methods: through image processing software, such as Photoshop et al, processed into a certain format, and processed into a certain format in its own system by scanner interface TWAIN . This interface is provided when installing the scanner, which is actually a plugin plug-in, which controls the scanner through a series of functions; control the scanner by component technology. ---- Using the first method to reduce the complexity of programming, but the system is not integrated, the user is not convenient; the second method can directly control the scanner directly, can be available on programming The maximum flexibility and controllability; the third method can make full use of Delphi's visual components, safety, flexible, and freely utilize scanners. In fact, the third method is also based on TWAIN.DLL of the scanner interface. The method discusses this article uses the third. ---- Windows 9X provides a "image" option in its attachments, which uses an OCX component to control the scanner, a total of IMGEDIT, IMGANNTOOL, IMGSCAN, IMGADMIN, and these four components are basically Can fully control the scanner. The usage in Delphi is as follows: Select Install "Image" in Windows 9x. (Select Add / Remove Programs in the Control Panel, select "Install Windows", click the "Attachment" checkbox, then "Image" in the "Image") start Delphi, select "Component" "Import ActiveX Control" under menu item, then you can see "WANG Image Editing Control, WANG Image Scan Control, WANG Image Management Control, WANG Image Thumbnail Control", selecting these four items, Then click on the "Install" button. At this time, you can see the icon of the four components under the ActiveX tongue on the component panel. ---- IMGSCAN's main properties: filetype: The file type of the image (this component supports three: TIFF, BMP, AWD); Scanto: Return or set the purpose of the scan image; can be valued 0 (default ) Displays the scanned image. 1 Display the scanned image and write a file .2 Write the image into a file 3 to write the image into the file and display .4. Template mode Writing file 5 Fax Scanned Image Note: If you can get a default value 0, you must use it with the WANGEGEDIT component. DestImageControl: Wang Imgedit component name; ZOOM: The main method of the image of the image: OpenScanner: Open the scanner; Closescanner: Turn the scanner; startscan: Start scan; StopScan: Stop Scan ---- Imgedit's property is mainly Controlling the resolution of the scan image, the aspect of the image, whether it allows local selection to the image; the method mainly has a copy, cutting image to the paste board, copy image, rotation, depression, Mirror image; print, save, refresh image, etc. ---- Detailed instructions on the above four OCX components can be viewed in Delphi.
---- Below is some examples of using these two components: procedure tscanf.n1click (sender: Tobject); beginimgscan1.showselectscanner; // Select the installed scanner END in the system; procedure tscanf.n2click (sender: Tobject) Beginimgedit1.Zoom: = 100; // Setting the image of the IF not imgscan1.scanneravailable dam // If the selected scanner is not available in imgscan1.openscanner; // Open Scanner imgscan1.startscan; // Start scanning diagram like imgscan1.CloseScanner; // Close the scanner end; procedure Tscanf.N8Click (Sender: TObject); beginif (imgedit1.IsClipboardDataAvailable and imgedit1.ImageDisplayed) thenimgedit1.ClipboardPaste (selleft, seltop); // image pasting from the clipboard, initial coordinate parameters Imgedit end thereof a display area; procedure Tscanf.N1801Click (Sender: TObject); beginif imgedit1.ImageDisplayed thenimgedit1.Flip; // mirror image end; procedure Tscanf.N901Click (Sender: TObject); beginif rightward rotation of the image imgedit1.ImageDisplayed thenimgedit1.RotateRight // end; procedure Tscanf.N6Click (Sender: TObject); beginimgedit1.DrawSelectionRect (selleft, seltop, selwidth, selheight); // for selecting a partial image imgedit1.ClipboardCut (selleft , SELTOP, SELWIDTH, SELHEIGHT; // Cut selected area end; ---- Note: When using the copy and shear function of the IMGEDit component in Delphi, the following issues appear: ---- 1, if Overall image is selected There is no problem; ---- 2, if the local area is selected, the copy and the clipping area will drift; ---- 3, if Delphi is done is the client interface of the MS SQL backend database, then When the image content is written to the image field of the database, the BDE (database engine) will report an error. This is the bugs of Delphi3.0 and 4.0, 4.0 upgrade packages can solve this problem. --- As for the second question, you can solve this: Write a code in the IMGEDIT's OneSelectionRectDrawn event, save the boundary value of the selection area to four global variables, with previously saved variables before copying and clipping Options can be selected (of course, all this is done in the background, see the previous example). ---- Development Environment: Delphi4.0, HP Scanjet 4P Scanner; ---- Advanced Code.
unit scanu; interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Menus, ScanLib_TLB, ExtCtrls, AxCtrls, OleCtrls, ImgeditLib_TLB; typeTscanf = class (TForm) MainMenu1: TMainMenu; F1: TMenuItem; N15: TMenuItem; N1 : TMenuitem; N16: TMenuitem; N11: TMenuitem; N11: TMenuitem; N1: TMenuItem; C1: TMenuItem; N4: tMenuItem; E1: TMenuItem; N6: TMenuItem; N7: tMenuItem; N8: tMenuItem; N3: tMenuItem; N7: tMenuItem ; N9: TMenuItem; N1801: TMenuItem; N901: TMenuItem; N902: TMenuItem; H1: TMenuItem; N12: TMenuItem; N13: TMenuItem; ImgEdit1: TImgEdit; Bevel1: TBevel; ImgScan1: TImgScan; Bevel2: TBevel; procedure N4Click (Sender: TObject); procedure N1Click (Sender: TObject); procedure N2Click (Sender: TObject); procedure C1Click (Sender: TObject); procedure N8Click (Sender: TObject); procedure N1801Click (Sender: TObject); procedure N901Click (Sender: TObject) Procedure N902Click (sender: TOBJECT); Procedure N6Click (sender: TOBJECT); Procedure N7Click (sender: TOBJECT); Procedure Imgedit1SerectionRectDRAWN (Sender: T Object; Left, Top, Width, Height: Integer); procedure N11Click (Sender: TObject); private {Private declarations} publicselleft, seltop, selwidth, selheight: integer; {Public declarations} end; varscanf: Tscanf; implementation {$ R * .DFM} procedure Tscanf.N4Click (Sender: TObject); beginimgedit1.ClearDisplay; close; end; procedure Tscanf.N1Click (Sender: TObject); beginImgScan1.ShowSelectScanner; end; procedure Tscanf.N2Click (Sender: TObject); beginimgedit1. zoom: = 100; if not imgscan1.ScannerAvailable thenimgscan1.OpenScanner; imgscan1.StartScan; imgscan1.CloseScanner; end; procedure Tscanf.C1Click (Sender: TObject); beginif imgedit1.ImageDisplayed thenbeginimgedit1.ClearDisplay; imgedit1.zoom: = 100; end End; procedure tscanf.n8click (sender: TOBJECT);