代码如下: ImgScan1.ScanTo:=1;
ImgScan1.FileType:=3;
ImgScan1.PageOption:=6;
ImgScan1.Image:='.\Image\Id.bmp';
ImgScan1.OpenScanner;//打开扫描仪,装载驱动。
ImgScan1.StartScan;
ImgScan1.StopScan;//中断扫描。
ImgScan1.FileType:=3;
ImgScan1.PageOption:=6;
ImgScan1.Image:='.\Image\Id.bmp';
ImgScan1.OpenScanner;//打开扫描仪,装载驱动。
ImgScan1.StartScan;
ImgScan1.StopScan;//中断扫描。
解决方案 »
- delphi 关于对IC卡片具体块的内容写法
- ppReport1.print和ppReport1.printreport打印有什么区别?
- 修改这个SQL语句
- 图形点阵模提取
- [在线等待,急!马上给分!]Delphi 7里怎么删除Form,使的在“窗口查看”里看不到?
- fastreport的问题一切都搞好了, 但是关闭主程序的时候, 出现 invaild pointer
- 请问用dbexpress+delphi6开发oracle应用程式需要那些文件才可运行!
- BDE有没有指定提取数据的功能呢?
- 句柄是什么?请给我最通俗的解释!
- 谁有CREAK了的MMTOOLS或CD->MP3的控件?my e-mail:[email protected]
- 一个关于dbgrid的问题
- 如何能让 $define 跨单元有效
在Delphi中通过扫描仪获得所需的图象信息呢?不外乎有三种基本的方法:
通过图象处理软件,比如说Photoshop等,通过它们的扫描图象的功能,加工成一定格式的图象后再在自己的系统中利用;通过扫描仪接口Twain.DLL 。该接口是在安装扫描仪时提供的,它实际上是一个Plugin插件,它通过一系列函数来控制扫描仪;通过构件技术来控制扫描仪。---- 利用第一种方法能减少编程的复杂度,但是系统的集成度不高,用户使用上也不方便;第二种方法能在驱动程序级直接控制扫描仪,能在编程上提供最大的灵活性和可控性;第三种方法能充分利用Delphi的可视化构件技术,安全、灵活、自由地利用扫描仪。其实第三种方法也是建立在扫描仪接口Twain.DLL之上的。本文论述的方法就采用第三种。---- Windows9X在其附件中提供了“映象”可选件,该附件是采用OCX构件来控制扫描仪的,共有imgEdit、imgAnntool、imgScan、imgAdmin 四个,有这四个构件基本上就能完全控制扫描仪。在Delphi中的用法如下:在Windows9x中选择安装“映象”。(在控制面板中选择“添加/删除程序”,再选择“安装Windows”,点击“附件”复选框,然后从“详细资料”按钮中可以找到“映象”)启动Delphi,选择“Component”菜单项下的“Import ActiveX Control”,这时可以看到列表中有“Wang 图象编辑控制、Wang 图象扫描控制、Wang 图象管理控制、Wang 图象缩略图控制”,选中这四项,然后点击“Install”按钮,这时在构件面板上的ActiveX舌标下就可以看到这四个构件的图标。---- ImgScan 的主要属性:FileType:图象的文件类型(该构件支持三种:TIFF,BMP,AWD);ScanTo:返回或设置被扫描图象的目的;可取值 含义0 (缺省) 显示被扫描的图象.1 显示被扫描的图象并写入一个文件.2 把图象写入一个文件3 以模板方式把图象写入文件并显示.4 . 以模板方式把图象写入文件5 传真被扫描的图象注意:如果取缺省值0,必须和 Wang ImgEdit 构件配合使用。DestImageControl:Wang ImgEdit构件名;Zoom:图象的放缩比例ImgScan 的主要方法:OpenScanner :打开扫描仪;CloseScanner :关闭扫描仪;StartScan : 开始扫描;StopScan : 停止扫描 ---- ImgEdit 的属性主要是控制扫描图象的分辨率、图象的宽高、是否允许对图象进行局部选 择等;其方法主要有拷贝、剪切图象到粘贴板,从粘贴板复制图象,旋转、放缩、 镜象图象;打印、保存、刷新图象等。---- 关于上述四个OCX构件的详细使用说明可在Delphi中查看其自带的帮助系统。---- 下面是使用这两个构件的一些例子:procedure Tscanf.N1Click(Sender: TObject);beginImgScan1.ShowSelectScanner;//选择系统中已安装的扫描仪end;procedure Tscanf.N2Click(Sender: TObject);beginimgedit1.zoom:=100; //设置图象的放缩因子if not imgscan1.ScannerAvailable then//如果选择的扫描仪不可用imgscan1.OpenScanner;//打开扫描仪imgscan1.StartScan; //开始扫描图象imgscan1.CloseScanner; //关闭扫描仪end; procedure Tscanf.N8Click(Sender: TObject);beginif (imgedit1.IsClipboardDataAvailableand imgedit1.ImageDisplayed ) thenimgedit1.ClipboardPaste(selleft,seltop);//从剪贴板粘贴图象,其参数为Imgedit的显示区域的起始坐标end;procedure Tscanf.N1801Click(Sender: TObject);beginif imgedit1.ImageDisplayed thenimgedit1.Flip; //镜象图象end;procedure Tscanf.N901Click(Sender: TObject);beginif imgedit1.ImageDisplayed thenimgedit1.RotateRight //向右旋转图象end;procedure Tscanf.N6Click(Sender: TObject);beginimgedit1.DrawSelectionRect(selleft,seltop,selwidth,selheight);//进行图象局部选择imgedit1.ClipboardCut(selleft,seltop,selwidth,selheight);//剪切所选区域end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs;type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Button1: TButton;
Button3: TButton;
SaveDialog1: TSaveDialog;
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
hdib, testdib: hbitmap;
w, h: integer;
n: Integer;
end;var
Form1: TForm1;
procedure CallbackFxn(CurDib: THandle; index: Integer); stdcall; forward;
implementationuses MultiTWAIN;{$R *.dfm}procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
hDib := 0;
w := 0; h := 0;
testDib := 0;
TWAIN_RegisterCallback(CallbackFxn);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if image1.Picture<>nil
then
image1.Picture:=nil;
TWAIN_SelectImageSource(0);
hdib := TWAIN_AcquireNative(0, 0); n := TWAIN_GetNumDibs;
TestDib := TWAIN_GetDib(0);
CopyDibIntoImage(TestDib, Image1);
TWAIN_FreeNative(TestDib);
TestDib := 0;
end;procedure CallbackFxn(CurDib: THandle; index: Integer); stdcall;
begin
MessageBox(0, '扫描完成!', '提示', mb_ok);
end;--------------------的引用这个单元:
//////////////////////////////////////////////////////////////////////
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, CommDlg;// Some of the functions in EZTWAIN require unsigned integers. However,
// it was not until the recent release of Delphi 4 that Inprise implemented
// this; they did so with LongWord/Cardinal. As far as D2 and D3 go, this
// unit will attempt to substitute an Integer instead. I don't know if it'll
// work though!type
{$IFDEF VER100}
UnsignedInt32 = Cardinal;
{$ELSE}
UnsignedInt32 = Integer;
{$ENDIF}
hDibCallbackProc = procedure(curdib: THandle; n: Integer); stdcall;const
TWAIN_BW=1; { 1-bit per pixel, B&W (== TWPT_BW) }
TWAIN_GRAY=2; { 1,4, or 8-bit grayscale (== TWPT_GRAY) }
TWAIN_RGB=4; { 24-bit RGB color (== TWPT_RGB) }
TWAIN_PALETTE=8; { 1,4, or 8-bit palette (== TWPT_PALETTE) }
TWAIN_ANYTYPE=0; { any of the above } TWAIN_PRESESSION=1; { source manager not loaded }
TWAIN_SM_LOADED=2; { source manager loaded }
TWAIN_SM_OPEN=3; { source manager open }
TWAIN_SOURCE_OPEN=4; { source open but not enabled }
TWAIN_SOURCE_ENABLED=5; { source enabled to acquire }
TWAIN_TRANSFER_READY=6; { image ready to transfer }
TWAIN_TRANSFERRING=7; { image in transit } TWUN_INCHES=0;
TWUN_CENTIMETERS=1;
TWUN_PICAS=2;
TWUN_POINTS=3;
TWUN_TWIPS=4;
TWUN_PIXELS=5;{$L eztwain.obj}
function TWAIN_SelectImageSource(hwnd: HWND): Integer; stdcall; external;
function TWAIN_AcquireNative(hwnd: HWND; pixmask: Integer): HBitmap; stdcall; external;
procedure TWAIN_FreeNative(hDIB: HBitmap); stdcall external;
function TWAIN_AcquireToClipboard(hwndApp: HWND; wPixTypes: UnsignedInt32): Integer; stdcall; external;
function TWAIN_AcquireToFilename(hWndApp: HWND; pszFile: PChar): Integer; stdcall; external;
function TWAIN_IsAvailable: Integer; stdcall; external;
function TWAIN_EasyVersion: Integer; stdcall; external;
function TWAIN_State: Integer; stdcall; external;
procedure TWAIN_RegisterCallback(fxn: hDibCallbackProc); stdcall; external;
procedure TWAIN_UnRegisterCallback; stdcall; external;procedure TWAIN_ClearDibList; stdcall; external;
function TWAIN_GetNumDibs: Integer; stdcall; external;
function TWAIN_GetDib(n: Integer): THandle; stdcall; external;function TWAIN_DibDepth(hDib: HBitmap): Integer; stdcall; external;
function TWAIN_DibWidth(hDib: HBitmap): Integer; stdcall; external;
function TWAIN_DibHeight(hDib: HBitmap): Integer; stdcall; external;
function TWAIN_DibNumColors(hDib: HBitmap): Integer; stdcall; external;
function TWAIN_CreateDibPalette(hdib: HBitmap): Integer; stdcall; external; // HANDLE & HPALETTE, respectively
procedure TWAIN_DrawDibToDC(
hDC: HDC;
dx, dy, w, h: Integer;
hDib: HBitmap;
sx, sy: Integer
); stdcall; external;
function TWAIN_WriteNativeToFilename(hdib: hBitmap; pszFile: PChar): Integer; stdcall; external;
function TWAIN_WriteNativeToFile(hdib: HBitmap; fh: Integer): Integer; stdcall; external;
function TWAIN_LoadNativeFromFilename(pszFile: PChar): HBitmap; stdcall; external;
function TWAIN_LoadNativeFromFile(fh: Integer): HBitmap; stdcall; external;
procedure TWAIN_RegisterApp( nMajorNum,nMinorNum: integer;
nLanguage: integer;
nCountry: integer;
lpszVersion: PChar;
lpszMfg: PChar;
lpszFamily: PChar;
lpszProduct: PChar); stdcall; external;
procedure TWAIN_SetHideUI(fHide: Integer); stdcall; external;
function TWAIN_GetHideUI: Integer; stdcall; external;
function TWAIN_GetResultCode: UnsignedInt32; stdcall; external;
function TWAIN_GetConditionCode: UnsignedInt32; stdcall; external;
function TWAIN_LoadSourceManager: Integer; stdcall; external;
function TWAIN_OpenSourceManager(hwnd: HWND): Integer; stdcall; external;
function TWAIN_OpenDefaultSource: Integer; stdcall; external;
function TWAIN_EnableSource(hwnd: hWnd): Integer; stdcall; external;
function TWAIN_DisableSource: Integer; stdcall; external;
function TWAIN_CloseSource: Integer; stdcall; external;
function TWAIN_CloseSourceManager(hWnd: HWND): Integer; stdcall; external;
function TWAIN_UnloadSourceManager: Integer; stdcall; external;
function TWAIN_MessageHook(lpmsg: PMSG): Integer; stdcall; external;
procedure TWAIN_ModalEventLoop; stdcall; external;
procedure TWAIN_NativeXferGetAll(psmg: PMSG); stdcall; external; // for multiple xfers
function TWAIN_AbortAllPendingXfers: Integer; stdcall; external;
function TWAIN_WriteDibToFile(lpDIB: PBITMAPINFOHEADER; fh: Integer): Integer; stdcall; external;
function TWAIN_NegotiateXferCount(nXfers: Integer): Integer; stdcall; external;
function TWAIN_NegotiatePixelTypes(wPixTypes: UnsignedInt32): Integer; stdcall; external;
function TWAIN_GetCurrentUnits: Integer; stdcall; external;
function TWAIN_SetCurrentUnits(nUnits: Integer): Integer; stdcall; external;
function TWAIN_GetBitDepth: Integer; stdcall; external;
function TWAIN_SetBitDepth(nBits: Integer): Integer; stdcall; external;
function TWAIN_GetPixelType: Integer; stdcall; external;
function TWAIN_SetCurrentPixelType(nPixType: Integer): Integer; stdcall; external;
function TWAIN_GetCurrentResolution: double; // implemented below
function TWAIN_SetCurrentResolution(dRes: double): Integer; // implemented below
function TWAIN_SetCapOneValue(Cap: UnsignedInt32; ItemType: UnsignedInt32; ItemVal: LongInt): Integer; stdcall; external;
function TWAIN_GetCapCurrent(Cap: UnsignedInt32; ItemType: UnsignedInt32; pVal: Pointer): Integer; stdcall; external;
function TWAIN_DS(DG: LongInt; DAT: UnsignedInt32; MSG: UnsignedInt32; pData: Pointer): Integer; stdcall; external;
function TWAIN_Mgr(DG: LongInt; DAT: UnsignedInt32; MSG: UnsignedInt32; pData: Pointer): Integer; stdcall; external;procedure CopyDIBIntoImage(hDIB: THandle; Image: TImage);implementation{ The procedures implemented below are the ones which use floating point numbers }const
ICAP_XRESOLUTION = $1118;
ICAP_PIXELTYPE = $0101;
TWTY_FIX32 = $0007;
TWTY_UINT16 = $0004;type
TW_FIX32 = record
Whole: SmallInt;
Frac: Word;
end;function ToFix32(r: Double): UnsignedInt32;
var
fix: TW_FIX32;
v: Integer;
begin
v := Round(r * 65536.0 + 0.5);
fix.Whole := ShortInt(V shr 16);
fix.Frac := Word (v and $ffff);
ToFix32 := UnsignedInt32(fix);
end;function Fix32ToFloat(fix: TW_FIX32): double;
var
v: Integer;
begin
v := (Integer(fix.Whole) shl 16) or (UnsignedInt32(fix.frac) and $ffff);
Fix32ToFloat := v / 65536.0;
end;function TWAIN_GetCurrentResolution: double;
var
res: TW_FIX32;
begin
TWAIN_GetCapCurrent(ICAP_XRESOLUTION, TWTY_FIX32, @res);
TWAIN_GetCurrentResolution := Fix32ToFloat(res);
end;function TWAIN_SetCurrentResolution(dRes: double): Integer;
begin
TWAIN_SetCurrentResolution := TWAIN_SetCapOneValue(ICAP_XRESOLUTION, TWTY_FIX32, ToFix32(dRes));
end;(*************************************************)procedure CopyDIBIntoImage(hDIB: THandle; Image: TImage);
var
DibW, DibH, oldw, oldh: integer;
begin
Oldw := Image.Width;
Oldh := Image.Height;
DibW := TWAIN_DibWidth(hDib);
DibH := TWAIN_DibHeight(hDib);
Image.Width := DibW; // temporarily enlarge image to ensure the whole
Image.Height := DibH; // DIB gets copied
TWAIN_DrawDibToDC(Image.Canvas.Handle, 0, 0, DibW, DibH, hDIB, 0, 0);
Image.Width := oldw;
Image.Height := oldh;
end;
end.
ImgScan1.FileType:=3;
ImgScan1.PageOption:=6;
ImgScan1.Image:='.\Image\Id.bmp';
ImgScan1.OpenScanner;//打开扫描仪,装载驱动。
ImgScan1.StartScan;
ImgScan1.ScanTo:=2;
// ImgScan1.StopScan;//中断扫描。
ImgScan1.PageOption:=0;//改成0试试
ImgScan1.Image:='.\Image\Id.bmp';
ImgScan1.OpenScanner;//打开扫描仪,装载驱动。
ImgScan1.StartScan;
ImgScan1.ScanTo:=2;//改成2
// ImgScan1.StopScan;//中断扫描。