title: scanning an image for a certain pixel color in java
body: <p>I'm working on a project and quiet new to java. I want to scan an image pixel by pixel for a certain color, i.e. cyan and then print the coordinates of that pixel color. The code runs, creates an output file but doesn't write anything to it.
  Can somebody please help me with it to find the errors. I also want to know how to read a <code>.tiff</code> file in java while using the same code.</p>
  
  <p>Java Code:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.image.BufferedImage;
  import java.io.BufferedWriter;
  import java.io.File;
  import java.io.FileWriter;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  
  public class GetPixelColor {
  
      //int y, x, tofind, col;
      /**
       * @param args the command line arguments
       * @throws IOException  
       */
      public static void main(String args[]) throws IOException {
          try {
              //read image file
              File file1 = new File("E:\\birds.jpg");
              BufferedImage image1 = ImageIO.read(file1);
  
              //write file
              FileWriter fstream = new FileWriter("E:\\pixellog1.txt");
              BufferedWriter out = new BufferedWriter(fstream);
  
              //color object
              //Color cyan = new Color(0, 255, 255);
  
              //find cyan pixels
              for (int y = 0; y &lt; image1.getHeight(); y++) {
                  for (int x = 0; x &lt; image1.getWidth(); x++) {
  
                    int c = image1.getRGB(x,y);
                    Color color = new Color(c);
  
                    //int  red = (c &amp; 0x0000FFFF) &gt;&gt; 16;
                    //int  green = (c &amp; 0x0000FFFF) &gt;&gt; 8;
                    //int  blue = c &amp; 0x0000FFFF;
  
                     //if (cyan.equals(image1.getRGB(x, y)){
  
                     if (color.getRed() &lt; 30 &amp;&amp; color.getGreen() &gt; 255 &amp;&amp; color.getBlue() &gt; 255) {
                          out.write("CyanPixel found at=" + x + "," + y);
                          out.newLine();
  
                      }
                  }
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>