Control scanner in Delphi

zhaozj2021-02-17  54

[Delphi] Controls the scanner in Delphi ---- When using the Delphi development information management system, you often process images, 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, through their scanning image, processing into a certain format, and use it in its own system;

TWAIN.DLL via the scanner. This interface is provided when the scanner is installed, which is actually a plugin plugin, which controls the scanner through a series of functions;

The scanner is controlled by component techniques. ---- 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, then select "Install Windows", click the "Attachment" checkbox, then "Image" from the Details button)

Start Delphi, select "Import ActiveX Control" under the "Component" menu item, then you can see "Wang Image Editing Control, WANG Image Scan Control, WANG Image Management Control, WANG Image Thumbnail Control) ", Select these four items, then click" 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 types: TIFF, BMP, AWD);

Scanto: Returns or sets the purpose of the scan image; the value enclosure 0 (default) displays the scanned image. 1 Display the scanned image and writes a file .2 Write the image into a file 3 Write the image into the file and display in a template mode. 4. Tags like a template to write the image 5 fax scanned image Note: If you take the default value 0, you must use the WANGEGEDit component. DestimageControl: Wang Imgedit component name; ZOOM: Image of the image

Main Method of IMGSCAN: OpenScanner: Open the scanner; Closescanner: Turn off the scanner; startscan: Start scanning; StopScan: Stop scan

---- Imgedit is mainly controlled by controlling the resolution of the scanning image, and whether the image is wide, whether it is partially selected for the image; the method mainly has a copy, cut image to the paste, from the paste board Copy image, rotation, confining, mirror image; print, save, refresh image, etc. ---- Detailed instructions on the above four OCX components can be viewed in Delphi. ---- The following is some examples of using these two components:

Procedure tscanf.n1click (sender: TOBJECT); beginimgscan1.showselectscanner; file: // Select the installed scanner End in the system; procedure tscanf.n2click (sender: Tobject); beginimgedit1.zoom: = 100; file: // Setting Image of the IFSCAN1.SCANNAVAILALALALALALSCAN1.SCANNNERAVAILALABLE THEN1.SCANNNERAVAILABLE THEN1.OPENSCANNER; / / Open Scanner imgscan1.startscan; file: // Start Scan image Imgscan1.closecanner; File: // Turn off the scanner END;

// starting from clipboard image, which is a parameter display area Imgedit: procedure Tscanf.N8Click: file; (Sender TObject); beginif (imgedit1.IsClipboardDataAvailable and imgedit1.ImageDisplayed) thenimgedit1.ClipboardPaste (selleft, seltop) Coordinate end;

Procedure tscanf.n1801click (sender: Tobject); beginif meansdit1.imagedisplayed tellit1.flip; file: // mirror image END;

procedure Tscanf.N901Click (Sender: TObject); beginif imgedit1.ImageDisplayed thenimgedit1.RotateRight file: // Rotate Right image end; procedure Tscanf.N6Click (Sender: TObject); beginimgedit1.DrawSelectionRect (selleft, seltop, selwidth, selheight) ; // Motion image part selectimgedit1.clipboardcut (Selleft, SELTOP, SELWIDTH, SELHEIGHT); // Cut the selected area END;

---- Note: When using the copy and shear function of the IMGEDit component in Delphi, the following issues appear: ---- 1, if you choose the entire image, there is no problem; ---- 2, If the local area is selected, the copy and the clippers will drift; ---- 3, if Delphi is done is the client interface of the MS SQL backend database, then write the image of the image to the database. When in the field, 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

---- Additional code. Unit scanu;

Interface

Useswindows, 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; N2: TMenuitem; N16: TMenuItem; N11: TMenuItem; N5: TMenuitem; C1: TMenuItem; N11: TMenuItem; E1: TMENUITEM; N6: TMenuItem; N7: TMenuItem; N8: TMenuItem; N3: TMenuItem; N10: 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 ImgEdit1SelectionRectDrawn (Sender: TObject Left, Top, Width, Height: Integer; Procedure N11Click (Sender: Tobject); Private {Private Declarations} PublicSelleft, SELTOP, SELWIDTH, SELHEIGHT: INTEGER; {Pub Lic Declarations}}} End; Varscanf: Tscanf; Implementation

{$ R * .dfm}

Procedure tscanf.n4click (sender: TOBJECT); beginimgedit1.cleardisplay; close;

Procedure tscanf.n1click (sender: TOBJECT); beginimgscan1.showselectscanner;

Procedure tscanf.n2click (sender: TOBJECT); beginimgedit1.zoom: = 100; if not imgscan1.scanneravailable tellnscan1.openscanner; imgscan1.startscan; Imgscan1.closecanner; End;

Procedure tscanf.c1click (sender: TOBJECT); Beginif Imgedit1.Imagedisplayed Thenbeginimgedit1.cleardisplay; IMGEDIT1.ZOOM: = 100; end;

Procedure tscanf.n8click (sender: TOBJECT); Beginif (IMGEDIT1.ISClipboardDataavailable and Imgedit1.ImageDisplayed).

procedure Tscanf.N1801Click (Sender: TObject); beginif imgedit1.ImageDisplayed thenimgedit1.Flip; end; procedure Tscanf.N901Click (Sender: TObject); beginif imgedit1.ImageDisplayed thenimgedit1.RotateRightend;

Procedure tscanf.n902click (sender: TOBJECT); beginif means; end;

Procedure tscanf.n6click (sene: TOBJECT); Beginimgedit1.drawSelectionRect (Selleft, Seltop, Selwidth, Selheight); IMGET1.CLIPBoardcut (Selleft, SELTOP, SELWIDTH, SELHEIGHT); END;

Procedure tscanf.n7click (sene: TOBJECT); Beginimgedit1.drawSelectionRect (Selleft, Seltop, Selwidth, Selheight); IMGEDIT1.CLIPBOARDCOPY (Selleft, Seltop, Selwidth, Selheight); END;

procedure Tscanf.ImgEdit1SelectionRectDrawn (Sender: TObject; Left, Top, Width, Height: Integer); beginif ((width = 0) and (height = 0)) thenbeginn3.Enabled: = false; n6.Enabled: = false; n7. Enabled: = false; sellet: = top; selWidth: = width; selheight: = height; endelse beginn6.enable: = true; n7.enable: = true; selleft: = left; sellet: = top; SEFT; SELLEFT: = LEFT; SELTOP: = TOP; SELWIDTH: = Width; Selheight: = Height; end;

procedure Tscanf.N11Click (Sender: TObject); beginif not imgedit1.IsClipboardDataAvailable thenif imgedit1.imagedisplayed thenimgedit1.ClipboardCopy (0,0, imgedit1.Width, imgedit1.Height); end; end.

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

New Post(0)