Created
December 26, 2018 04:04
-
-
Save arwankhoiruddin/d2b8e5a1650f9e97b69656d6a3358b94 to your computer and use it in GitHub Desktop.
Find the difference between two display using java.awt.Robot and Sikuli library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.image.BufferedImage; | |
import org.sikuli.script.*; | |
import javax.imageio.ImageIO; | |
import static controller.ImageController.isExist; | |
import static crfs.CP.contentEquals; | |
public class ScreenShotDifference { | |
public static void main(String[] args) throws Exception { | |
int white = new Color(255, 255, 255).getRGB(); | |
int black = new Color(0, 0, 0).getRGB(); | |
Screen s = new Screen(); | |
try { | |
Robot robot = new Robot(); | |
Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); | |
long start = System.nanoTime(); | |
BufferedImage bufferedImage1 = robot.createScreenCapture(area); | |
System.out.println("First image taken"); | |
s.wait(3.); | |
System.out.println("Start take the second image"); | |
BufferedImage bufferedImage2 = robot.createScreenCapture(area); | |
BufferedImage diff = bufferedImage1; | |
for (int i=0; i<bufferedImage1.getWidth(); i++) { | |
for (int j=0; j<bufferedImage1.getHeight(); j++) { | |
if (bufferedImage1.getRGB(i, j) == bufferedImage2.getRGB(i, j)) { | |
diff.setRGB(i, j, black); | |
} else { | |
diff.setRGB(i, j, white); | |
} | |
} | |
} | |
ImageIO.write(diff, "png", new File("/Users/arwankhoiruddin/Desktop/diff.png")); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment