【问题标题】:take screen shot of a specific area in sikuli for eclipse gui为 Eclipse gui 拍摄 sikuli 中特定区域的屏幕截图
【发布时间】:2018-04-22 18:25:00
【问题描述】:

我正在尝试在运行测试执行时截取屏幕截图。 我使用 sikuli java 使用以下代码:

 Screen screen = new Screen();
 ImageIO.write(screen.capture().getImage(), "png", new File(file-location+"1.png"));

我使用的另一种方法是 java awt:

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    Rectangle screenRect = new Rectangle(screenSize);
    Robot robot = new Robot();
    BufferedImage image5 = robot.createScreenCapture(screenRect);
    ImageIO.write((RenderedImage) image5, "png", new File(AppConstant.IMAGE_DIR+"1.png"));

但问题是,它正在使用 Ubuntu 菜单栏截取我的整个屏幕。我想要的是只截取我的 eclipse 窗口的屏幕截图,一个特定的区域。

【问题讨论】:

  • 您需要找到 Eclipse 窗口的大小和位置,或者您要截屏的任何内容,然后使用这些尺寸对 Robot 类进行截屏。
  • 类似:BufferedImage img = robot.createScreenCapture(new Rectangle(x, y, width, height));?????
  • 或者我只能通过哪种方式获得我的eclipse窗口大小的屏幕尺寸?

标签: java automation sikuli


【解决方案1】:

一种方法是使用App 类。因此,如果您像这样启动 Eclipse 进程:

// You might need to provide full path here
App app = App.open("eclipse.exe");

然后您可以使用capture 方法和app 区域作为参数。 app区域可以通过window()方法获得。所以:

App app = App.open("eclipse.exe");
ImageIO.write(screen.capture(app.window()).getImage(), "png", new File("1.png")); 

【讨论】:

  • 不,我的应用程序不是这样打开的。我的应用程序是基于 Eclipse 的应用程序,我在运行测试时使用 sh 脚本打开它。
【解决方案2】:

您可以使用Sikuli App Class 执行此操作。例如。如果应用在运行测试时处于焦点位置,您可以使用以下方法:

Region appRegion = App.focusedWindow();
Screen screen = new Screen();
 ImageIO.write(screen.capture(appRegion).getImage(), "png", new File(file-location+"1.png"));

这样,根据您的要求仅捕获应用程序窗口,并且由于您现在有一个区域,您可以对其进行操作以增加/减小捕获的大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    相关资源
    最近更新 更多