Here you can find the source of compareImages(final BufferedImage img1, final BufferedImage img2)
Parameter | Description |
---|---|
img1 | First image for the comparison |
img2 | Second image for the comparison |
protected static Point[] compareImages(final BufferedImage img1, final BufferedImage img2)
//package com.java2s; //License from project: Open Source License import java.awt.Point; import java.awt.image.BufferedImage; import java.util.ArrayList; public class Main { /**//from ww w . j a va 2 s . c o m * Exact pixel by pixel compare. Images must have the same size * * @param img1 First image for the comparison * @param img2 Second image for the comparison * @return Point[] array that contains the coordinates of pixels that are different */ protected static Point[] compareImages(final BufferedImage img1, final BufferedImage img2) { if (img1.getWidth() != img2.getWidth() || img1.getHeight() != img2.getHeight()) { return null; } final ArrayList<Point> pixels = new ArrayList<>(); for (int x = 0; x < img1.getWidth(); x++) { for (int y = 0; y < img1.getHeight(); y++) { // if the RGB values of 2 pixels differ if (img1.getRGB(x, y) != img2.getRGB(x, y)) { pixels.add(new Point(x, y)); } } } return pixels.toArray(new Point[pixels.size()]); } }