title: What's wrong with ImageIO.write. It doesn't write the image back or show it?
body: <p>The purpose of this program in to get the negative of a gray scale image. When I run, nothing appears and the resulted image doesn't show up. After debugging, everything works fine except the ImageIO.write function. Any idea why ?</p>
  
  <pre><code>import java.awt.BufferCapabilities;
  import java.awt.image.BufferedImage;
  import java.awt.image.WritableRaster;
  import java.io.File;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  
  
  public class emancv {
  
      public  static void main(String[] args){
      String filepath = "D:\\Eman Hamed\\Academics\\Fall 14\\Computer Vision\\flower.jpg";
          try {
                  BufferedImage bi = ImageIO.read(new File(filepath));
                  BufferedImage output = negative(bi);
                  ImageIO.write(output, "jpg", new File("D:\\Eman Hamed\\Academics\\Fall 14\\Computer Vision\\flower2.jpg"));
  
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
  
      public static BufferedImage negative(BufferedImage bi){
          WritableRaster myImage = bi.copyData(null);
          WritableRaster myImage2 = bi.copyData(null);
          for(int i =0; i&lt; myImage2.getHeight(); i++)
              for(int j =0; j&lt;myImage2.getWidth(); j++)
              {
                  int value = 255 - myImage.getSample(j, i, 0);
                  myImage2.setSample(j, i, 0, value);
              }
           BufferedImage res= new BufferedImage(bi.getWidth(),bi.getHeight(),BufferedImage.TYPE_BYTE_GRAY);
          res.setData(myImage2);
          return res;
              }
          }
  </code></pre>