Java BufferedImage Compare compare(BufferedImage a, BufferedImage b)

Here you can find the source of compare(BufferedImage a, BufferedImage b)

Description

Method used to compare two given images

License

Open Source License

Parameter

Parameter Description
a The image to compare against
b The image to compare with

Return

Weather or not the two images are the same

Declaration

public static boolean compare(BufferedImage a, BufferedImage b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;

public class Main {
    /**/*  w ww .  jav  a 2  s.co m*/
     * Method used to compare two given images
     * @param a The image to compare against
     * @param b The image to compare with
     * @return Weather or not the two images are the same
     */
    public static boolean compare(BufferedImage a, BufferedImage b) {
        int aData = 0, bData = 0;

        for (int xPos = 0; xPos < a.getWidth(); xPos++) {
            for (int yPos = 0; yPos < a.getHeight(); yPos++) {
                aData = a.getRGB(xPos, yPos);
            }
        }

        for (int xPos = 0; xPos < b.getWidth(); xPos++) {
            for (int yPos = 0; yPos < b.getHeight(); yPos++) {
                bData = b.getRGB(xPos, yPos);
            }
        }

        return aData == bData;
    }
}

Related

  1. compare(BufferedImage p1, BufferedImage p2)
  2. compareBufferedImages(BufferedImage bufferedImage1, BufferedImage bufferedImage2)
  3. compareImage(BufferedImage biA, BufferedImage biB)
  4. compareImage(BufferedImage img1, BufferedImage img2)