I used
BufferedImage bi= new BufferedImage(320,240,BufferedImage.TYPE_BYTE_GRAY);
ImageIO.write(bi, "png", outputfile);
to save an image but save a black image. I can not understand what is the problem.
I used
BufferedImage bi= new BufferedImage(320,240,BufferedImage.TYPE_BYTE_GRAY);
ImageIO.write(bi, "png", outputfile);
to save an image but save a black image. I can not understand what is the problem.
As it was suggested already, the default pixel values are zeros (RGB(0,0,0)) in a BufferedImage
, so by this line:
BufferedImage bi= new BufferedImage(320,240,BufferedImage.TYPE_BYTE_GRAY);
you create a black image. So the result is exactly what is expected in this case.
If you want to create a white one for example, you can do this:
BufferedImage bi= new BufferedImage(320,240,BufferedImage.TYPE_BYTE_GRAY);
Graphics gc = bi.getGraphics();
gc.setColor(Color.white);
gc.fillRect(0,0,320,240);
before saving.