java の Graphics2D を使って差分画像を作成するプログラムを作ってみました。

    public static void createXORResult(File fa, File fb, File result) throws IOException {
        BufferedImage image_a = ImageIO.read(fa);
        BufferedImage image_b = ImageIO.read(fb);

1
2
3
4
5
6
7
8
    Graphics2D g2d = (Graphics2D) image_a.createGraphics();  
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    g2d.setXORMode(Color.BLACK);
    g2d.drawImage(image_b, <span class="synConstant">null</span>, <span class="synConstant">0</span>, <span class="synConstant">0</span>);

    ImageIO.write(image_a, <span class="synConstant">&quot;png&quot;</span>, result);
}