WEB开发网
开发学院软件开发Delphi Delphi图象截取编程示例 阅读

Delphi图象截取编程示例

 2006-02-04 13:53:29 来源:WEB开发网   
核心提示: 注意,本例在 Delphi7.0下调试通过///(一)建立项目 new Items-->PRojects-->MDI application (二)重新设计MDI子窗体--ChildWin,实现抓取的图象在ChildWin中显示,Delphi图象截取编程示例, 在ChildWin子窗体中去掉原有的M

注意,本例在 Delphi7.0下调试通过
///////////////////////////////////////////////////////////

(一)建立项目
  new Items-->PRojects-->MDI application
 
(二)重新设计MDI子窗体--ChildWin,实现抓取的图象在ChildWin中显示。
   在ChildWin子窗体中去掉原有的Memo1控件,添加Image控件,Image1.Align=alClient。
   Image1.AutoSize=ture表示原尺寸显示,Strech=false表示不按对象框显示。

(三)主界面修改
  1)去掉 menu,toolbar,ActionList 中与 paste,new 相关的项
  2)添加 PrinterSetupDialog1,SaveDialog 控件到MainForm .
   添加菜单项file\打印,属性name为filePrintItem;
   添加菜单项file\打印设置,属性enabled=false,name为filePrintSet;
   添加菜单项edit\Draw ,它的属性enabled=false ;
   添加菜单项edit\Preferences,设置它为包含字菜单(create Submenu);
   添加菜单项edit\Preferences\Configuration;
   添加菜单项edit\Preferences\ToolBar,它的checked=true,name=toolbarItem;
   添加菜单Image;
   添加菜单项Image\Capture Desktop;
   添加菜单项Image\Capture Area;
   添加菜单项Image\Capture Windows or Controls;
   添加菜单项Image\Capture Icon
  
   添加四个toolbar button 到 toolbar,对应Image菜单下的四个菜单项。
  
   添加四个Action到ActionList:cptDestop,cptArea,cptWindows,cptIcon;
   将Image菜单下的四个菜单项 的action属性分别对应上面四个Action;
   将新增的四个toolbar button的action属性分别对应上面四个Action。
  
  3)在Main单元中把implementation的uses CHILDWIN移到interface的uses中,
   添加ScrnCpt到interface的uses中;
   在TMainForm的public中添加定义:
     Child: TMDIChild;
     CaptureNum:integer;
     FileName:String;
     DefaultDirectory:string;
    
  4)在TMainForm添加私有函数:procedure Delay(msecs:integer)
procedure TMainForm.Delay(msecs:integer); //实现延时
var FirstTickCount:Longint;
begin
  FirstTickCount:=GetTickCount; //windows启动到现在的时间(豪秒)
  repeat
   begin
    Application.ProcessMessages; //中断程序让windows能响应发生的事件
   end;
  until ((GetTickCount-FirstTickCount)>=Longint(msecs));
end;

  5)修改[TMainForm.CreateMDIChild]过程:
   去掉变量var Child: TMDIChild,添加参数newFile
procedure TMainForm.CreateMDIChild(const Name: string;newFile:boolean);
begin
  Child := TMDIChild.Create(Application); { create a new MDI child window }
  Child.Caption := Name;
  if (not newFile)and(Name<>'') then begin
   Child.Image1.Picture.Bitmap.LoadFromFile(Name);
   Child.HorzScrollBar.Range := Child.Image1.Picture.Width;
   Child.VertScrollBar.Range := Child.Image1.Picture.Height;
  end;
end;  

Tags:Delphi 图象 截取

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接