Skip to content

Instantly share code, notes, and snippets.

/diff.cs Secret

Created September 17, 2017 17:44
Show Gist options
  • Select an option

  • Save anonymous/34abe26431e21920e83c6cf7a57a852c to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/34abe26431e21920e83c6cf7a57a852c to your computer and use it in GitHub Desktop.
public Image imageDiff(Image img1, Image img2){
Bitmap gazou1 = new Bitmap(img1);
Bitmap gazou2 = new Bitmap(img2);
//画像サイズが小さい方に合わせる
int ht = gazou1.Height;
int wt = gazou1.Width;
if (gazou1.Width > gazou2.Width){
wt = gazou2.Width;
}
if (gazou1.Height > gazou2.Height){
ht = gazou2.Height;
}
Bitmap btDiff = new Bitmap(wt,ht);
Image imgDiff;
for (int i = 0; i < wt; i++){
for (int j = 0; j < ht; j++){
if (gazou1.GetPixel(i, j) == gazou2.GetPixel(i, j)){
//一致ならば比較元のピクセルデータをそのまま格納
btDiff.SetPixel(i, j, gazou1.GetPixel(i, j));
}else{
//不一致ならば結果に紫色を格納
btDiff.SetPixel(i, j, Color.BlueViolet);
}
}
}
imgDiff = btDiff;
return imgDiff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment