title: Converting a color image to grayscale is showing black image in java
body: <p>I am trying to convert an image to gray scale image using Java. The problem here is, when I am trying to save that image after converting into gray scale it is showing a black image. I am little unaware of this image conversions. I would like to know why it is not working, and your answers will help me in my project. Thank you. </p>
  
  <pre><code>BufferedImage image = ImageIO.read(fileContent);
  File outputFile = new File(date1);
  ImageIO.write(image1, "png", outputFile);  
  </code></pre>
  
  <p>(This is the color image obtained from html page, and it is working properly. And when I am trying to display/save this image, color image is visible. But the problem arises when the below code is used to convert color image to gray scale image.)</p>
  
  <pre><code>     BufferedImage image1 = new BufferedImage(width, height,BufferedImage.TYPE_BYTE_GRAY);  
       Graphics graphics = image1.getGraphics();  
       graphics.drawImage(image, 0, 0, null);  
       graphics.dispose();
  
       File outputFile = new File(date1);
       ImageIO.write(image1, "png", outputFile);  
  </code></pre>