Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bendbits.imagediff;
- import javax.imageio.ImageIO;
- import java.awt.*;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- public class ImageDiff {
- public static void main(String[] args) throws IOException {
- BufferedImage image1 = ImageIO.read(new File("C:\\Users\\Steve\\Desktop\\image1.png"));
- BufferedImage image2 = ImageIO.read(new File("C:\\Users\\Steve\\Desktop\\image2.png"));
- BufferedImage diff = new BufferedImage(image1.getWidth(), image1.getHeight(), image1.getType());
- for (int col = 0; col < image1.getWidth(); col++) {
- for (int row = 0; row < image1.getHeight(); row++) {
- int rgb1 = image1.getRGB(col, row);
- int rgb2 = image2.getRGB(col, row);
- Color col1 = new Color(rgb1);
- Color col2 = new Color(rgb2);
- Color diffCol = new Color(Math.abs(col1.getRed() - col2.getRed()), Math.abs(col1.getGreen() - col2.getGreen()), Math.abs(col1.getBlue() - col2.getBlue()));
- diff.setRGB(col, row, diffCol.getRGB());
- }
- }
- ImageIO.write(diff, "png", new File("C:\\Users\\Steve\\Desktop\\diff.png"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment