Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9.  
  10. namespace ImageComparison
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. static string fname1, fname2;
  20. Bitmap img1, img2;
  21. int count1 = 0, count2 = 0;
  22. bool flag = true;
  23.  
  24. private void Form1_Load(object sender, EventArgs e)
  25. {
  26. progressBar1.Visible = false;
  27. pictureBox1.Visible = false;
  28. }
  29.  
  30. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  31. {
  32. openFileDialog1.FileName = "";
  33. openFileDialog1.Title = "Images";
  34. openFileDialog1.Filter = "All Images|*.jpg; *.bmp; *.png";
  35.  
  36. openFileDialog1.ShowDialog();
  37. if (openFileDialog1.FileName.ToString() != "")
  38. {
  39. fname1 = openFileDialog1.FileName.ToString();
  40. }
  41. }
  42.  
  43. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  44. {
  45. openFileDialog2.FileName = "";
  46. openFileDialog2.Title = "Images";
  47. openFileDialog2.Filter = "All Images|*.jpg; *.bmp; *.png";
  48.  
  49. openFileDialog2.ShowDialog();
  50. if (openFileDialog2.FileName.ToString() != "")
  51. {
  52. fname2 = openFileDialog2.FileName.ToString();
  53. }
  54. }
  55.  
  56. private void button1_Click(object sender, EventArgs e)
  57. {
  58. progressBar1.Visible = true;
  59.  
  60. string img1_ref, img2_ref;
  61. img1 = new Bitmap(fname1);
  62. img2 = new Bitmap(fname2);
  63.  
  64. progressBar1.Maximum = img1.Width;
  65. if (img1.Width == img2.Width && img1.Height == img2.Height)
  66. {
  67. for (int i = 0; i < img1.Width; i++)
  68. {
  69. for (int j = 0; j < img1.Height; j++)
  70. {
  71. img1_ref = img1.GetPixel(i, j).ToString();
  72. img2_ref = img2.GetPixel(i, j).ToString();
  73. if (img1_ref != img2_ref)
  74. {
  75. count2++;
  76. flag = false;
  77. break;
  78. }
  79. count1++;
  80. }
  81. progressBar1.Value++;
  82. }
  83.  
  84. if (flag == false)
  85. MessageBox.Show("Sorry, Images are not same , " + count2 + " wrong pixels found");
  86. else
  87. MessageBox.Show(" Images are same , " + count1 + " same pixels found and " + count2 + " wrong pixels found");
  88. }
  89. else
  90. MessageBox.Show("can not compare this images");
  91.  
  92. this.Dispose();
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement