我只是在谷歌上搜索下面的代码,了解如何比较两个为使用 Selenium Java而编写的图像。但是,我需要像下面的方式比较图像文件,但在Ruby Selenium 中。请指导我一些与Ruby Selenium中的 getData()、 getNumBands ()、getWidth()、getHeight()、getSample()相同的方法?非常感谢。
try {
original = ImageIO.read(new File(
"originalFile"));
copy = ImageIO.read(new File("copyFile"));
ras1 = original.getData();
ras2 = copy.getData();
//Comparing the the two images for number of bands,width & height.
if (ras1.getNumBands() != ras2.getNumBands()
|| ras1.getWidth() != ras2.getWidth()
|| ras1.getHeight() != ras2.getHeight()) {
ret=false;
}else{
// Once the band ,width & height matches, comparing the images.
search: for (int i = 0; i < ras1.getNumBands(); ++i) {
for (int x = 0; x < ras1.getWidth(); ++x) {
for (int y = 0; y < ras1.getHeight(); ++y) {
if (ras1.getSample(x, y, i) != ras2.getSample(x, y, i)) {
// If one of the result is false setting the result as false and breaking the loop.
ret = false;
break search;
}