gpt4 book ai didi

java - 截图: RasterFormatException (y+ height) is outside Raster

转载 作者:行者123 更新时间:2023-12-02 05:01:31 28 4
gpt4 key购买 nike

按照其他帖子的建议,使用 Selenium Webdriver 截取特定 UI 元素的屏幕截图,我使用 getSubimage 方法来捕获屏幕元素。但是,接收失败异常。

我不确定 uielement 的 getLocation().getX() 和 getSize().getWidth().getX() 的区别。如果有人可以澄清这一点,因为在 WritableRaster 方法的条件内它总是检查 y+height

File imgSrc=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
Point point = uiElem.getLocation();
Point bottomright = new Point(uiElem.getSize().getWidth(),
uiElem.getSize().getHeight());
int xcord = point.getX();
int ycord = point.getY();

BufferedImage img;
try {
img = ImageIO.read(imgSrc);
BufferedImage dest = img.getSubimage(xcord, ycord, bottomright.getX(), bottomright.getY());
ImageIO.write(dest, "png", imgSrc);
FileUtils.copyFile(imgSrc, new File(".\\Screenshots\\123.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

在调试时,我注意到img(宽度1366,高度=613)。 getSubImage() 有 (194,1335,960,15)。 createWritableChildMethod 内的条件 (y+ height) >(this.minY + this.height ) 总是会失败。那么,任何人都可以指出哪里出了问题,也没有意义,为什么我们添加子图像的 (y+height) 更大?

最佳答案

找到了一种解决方法,只是注意到最好直接在 UIElement 上使用 getScreenshotAs() ,而不需要对元素进行大量操作。

public void takeSmallScreenshot(WebDriver driver, WebElement uiElem)
{
File uiElementSrc = uiElem.getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(uiElementSrc, new File(".\\Screenshots\\"+uiElem.getText().substring(0,5)+".png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

关于java - 截图: RasterFormatException (y+ height) is outside Raster,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56382626/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com