欢迎光临
我们一直在努力

delphi图象截取编程示例(1)_delphi教程

建站超值云服务器,限时71元/月


注意,本例在 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;    

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » delphi图象截取编程示例(1)_delphi教程
分享到: 更多 (0)