Skip to content

Instantly share code, notes, and snippets.

@goofmint

goofmint/diff2.java

Last active Sep 21, 2017
Embed
What would you like to do?
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import com.htmlhifive.pitalium.core.*;
import com.htmlhifive.pitalium.image.util.*;
import com.htmlhifive.pitalium.image.model.*;
class Diff {
public static void main(String args[]){
try {
// 正とする画像
BufferedImage Image1 = ImageIO.read(new File(args[0]));
// 比較対象の画像
BufferedImage Image2 = ImageIO.read(new File(args[1]));
// 比較実行
ImageComparedResult result = ImageUtils.compare(
Image1, null, Image2, null,
new CompareOption[] {
new CompareOption(
CompareOptionType.IGNORE_CLEAR_PIXELS
)
}
);
// 結果の確認
if (result.isFailed()) {
// 違いがある場合
// 差分を書き出し
DiffPoints diffPoints = (DiffPoints) result;
final BufferedImage diffImage = ImageUtils.getDiffImage(
Image1,
Image2,
diffPoints
);
// ファイルに書き出し
ImageIO.write(diffImage, "png", new File(args[2]));
}
} catch(IOException e) {
System.err.println(e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment