Ranorex中如何进行截屏保存图片

在讲截屏保存之前,先介绍一下,Ranorex的代码结构。Renorex的代码分为录制代码和用户代码两类,分别独立存储,录制代码可以看,但无法修改,所以用户要想修改脚本只能在用户代码文件中进行编写,写好的代码可以动作中进行添加。

直接讲步骤:

  1. 在需要截屏保存的动作下面,右击-“+Add New Actions”\“User Code”\“New User Code Method”,新建用户代码(也可以选择已经写好的用户代码);
     
    2,输入名称“img”(自己定义);
     
    3,双击“User Code”行,打开代码编写界面;
     

4,我选择的开发语言是c#,在引用部分需要添加“using System.Windows.Forms;”

5,在img()代码段中输入
              Screen scr = Screen.PrimaryScreen;
                 Rectangle rc = scr.Bounds;
                 int iWidth = rc.Width;
                 int iHeight = rc.Height;
                 Bitmap myImage = new Bitmap(iWidth, iHeight);
                 Graphics gl = Graphics.FromImage(myImage);
                 gl.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
                 myImage.Save(@"d:\\img1.jpeg");
 
6,点击保存,执行即可,在D盘根目录下生成了一个新文件img1.jpg。

猜你喜欢

转载自blog.csdn.net/qq19970496/article/details/85686317
今日推荐