Here you can find the source of findDifference(BufferedImage img2, BufferedImage img1)
public static BufferedImage findDifference(BufferedImage img2, BufferedImage img1)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.Raster; public class Main { public static BufferedImage findDifference(BufferedImage img2, BufferedImage img1) { BufferedImage img = new BufferedImage(img2.getWidth(), img2.getHeight(), img2.getType()); Graphics2D g2d = img.createGraphics(); Raster data = img.getData(); for (int x = data.getMinX(); x < data.getWidth(); x++) { for (int y = data.getMinY(); y < data.getHeight(); y++) { if ((img2.getRGB(x, y) >> 24) == 0x00 && (img1.getRGB(x, y) >> 24) != 0x00) { g2d.setColor(new Color(img1.getRGB(x, y))); g2d.drawRect(x, y, 1, 1); }/*w w w. j ava2 s .co m*/ } } g2d.dispose(); return img; } }