Skip to content

Instantly share code, notes, and snippets.

@goofmint
Last active September 21, 2017 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofmint/914f6cadb59c9e5f3d6b3239d09bc48e to your computer and use it in GitHub Desktop.
Save goofmint/914f6cadb59c9e5f3d6b3239d09bc48e to your computer and use it in GitHub Desktop.
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.DEFAULT,
new DefaultComparisonParameters()
)
}
);
// 結果の確認
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