Advertisement
20myloves13

imageB

Nov 25th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. Bitmap img;
  2.  
  3. "Imagen.ImageLocation = openFileDialog1.FileName.ToString();"
  4. img = new Bitmap(openFileDialog1.FileName.ToString()); // Make a copy of the image in the Bitmap variable
  5.  
  6. Then go back to the design form and double click on the second button, this will lead you to the event, and then place the next code:
  7.  
  8. // First we declare the variable that will make the strig that will be printed in the textbox  
  9. string texto = "";
  10. //The we make the cicles to read pixel by pixel and we make the comparation with the withe color.  
  11. for (int i = 0; i < img.Width; i++)
  12. {
  13.     for (int j = 0; j < img.Height; j++)
  14.     {
  15.         //When we add the value to the string we should invert the
  16.         order because the images are reading from top to bottom  
  17.         //and the textBox is write from left to right.  
  18.         if (img.GetPixel(j, i).A.ToString() == "255" && img.GetPixel(j,
  19.         i).B.ToString() == "255" && img.GetPixel(j, i).G.ToString() ==
  20.         "255" && img.GetPixel(j, i).R.ToString() == "255")
  21.         {
  22.             texto = texto + "0";
  23.         }
  24.         else
  25.         {
  26.             texto = texto + "1";
  27.         }
  28.     }
  29.     texto = texto + "\r\n"; // this is to make the enter between lines  
  30. }
  31. //And finally we put the string to the textbox  
  32. txtArreglo.Text = texto;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement