英文:
Issue while comparing two images using Java & ImageMagick
问题
我有一个简单的解决方案来比较两张图片(两张 Chrome 浏览器的截屏)。为了获取图片,我使用了 AShoot 库。为了比较两张图片,我使用了 ImageMagic 工具。
```java
public Screenshot takeScreenshot() {
Screenshot elementScreenShot = new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(DriverManager.getWebDriver());
return elementScreenShot;
}
我使用 ImageMagic 来比较基准图片与新的图片 - 实际图片。但是经常会出现错误。一切都正常,但问题出在字段的角落处。
示例:
实际图片:
期望图片:
比较结果(ImageMagic 比较结果):
正如您所见,问题出在字段角落的几个像素上。我尝试了很多方法,但没有任何效果。
<details>
<summary>英文:</summary>
I have a simple solution to compare two images (two screenshots of Chrome browser). To get an image I use AShoot library. To compare two images I use ImageMagic tool.
public Screenshot takeScreenshot() {
Screenshot elementScreenShot = new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(DriverManager.getWebDriver());
return elementScreenShot;
}
I use ImageMagic to compare base image with new one - actual.
But very often I getting an error. Everything is ok but the problem is with corners of fields.
Example:
Actual:
[![enter image description here][1]][1]
Expected:
[![enter image description here][2]][2]
Result (ImageMagic compare result):
[![enter image description here][3]][3]
As you can see, the problem is with few pixels in the corner of the field. I tried many tricks but nothing happens.
[1]: https://i.stack.imgur.com/ZsDhX.png
[2]: https://i.stack.imgur.com/KCNVb.png
[3]: https://i.stack.imgur.com/Hnw3y.png
</details>
# 答案1
**得分**: 0
我观察到问题只出现在Chrome浏览器上。在Mozilla上一切正常。似乎在Chrome浏览器中渲染我们的应用程序时出现了问题。对于相同网站的10次执行,有7/10在字段角落存在差异。
<details>
<summary>英文:</summary>
I observe that issues occur only on the Chrome browser. On Mozilla everything it's OK. It seems that there is a problem in rendering our application in the Chrome browser. For 10 executions of this same site, 7/10 have differences in field corners.
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论