Guest User

Untitled

a guest
Jun 18th, 2020
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. package com.bendbits.imagediff;
  2.  
  3. import javax.imageio.ImageIO;
  4. import java.awt.*;
  5. import java.awt.image.BufferedImage;
  6. import java.io.File;
  7. import java.io.IOException;
  8.  
  9. public class ImageDiff {
  10. public static void main(String[] args) throws IOException {
  11. BufferedImage image1 = ImageIO.read(new File("C:\\Users\\Steve\\Desktop\\image1.png"));
  12. BufferedImage image2 = ImageIO.read(new File("C:\\Users\\Steve\\Desktop\\image2.png"));
  13.  
  14. BufferedImage diff = new BufferedImage(image1.getWidth(), image1.getHeight(), image1.getType());
  15.  
  16. for (int col = 0; col < image1.getWidth(); col++) {
  17. for (int row = 0; row < image1.getHeight(); row++) {
  18. int rgb1 = image1.getRGB(col, row);
  19. int rgb2 = image2.getRGB(col, row);
  20.  
  21. Color col1 = new Color(rgb1);
  22. Color col2 = new Color(rgb2);
  23.  
  24. Color diffCol = new Color(Math.abs(col1.getRed() - col2.getRed()), Math.abs(col1.getGreen() - col2.getGreen()), Math.abs(col1.getBlue() - col2.getBlue()));
  25. diff.setRGB(col, row, diffCol.getRGB());
  26. }
  27. }
  28.  
  29. ImageIO.write(diff, "png", new File("C:\\Users\\Steve\\Desktop\\diff.png"));
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment