Forum Stats

  • 3,759,510 Users
  • 2,251,557 Discussions
  • 7,870,689 Comments

Discussions

Java awt Graphics2D crisp pixel edges

MikeyJY
MikeyJY Member Posts: 2 Green Ribbon

I have this simple white noise generator:

public static void main(String[] args) throws Exception {

int width = 100;

  int height = 100;


  BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);


  Graphics2D g2d = bufferedImage.createGraphics();


  for(int i = 0;i<width;i++) {

for(int j = 0;j<=height;j++) {

   float noise = (float) Math.random();

   Color pixel = new Color(noise, noise, noise);

  

   g2d.setColor(pixel); 

   g2d.drawLine(i,j,i,j);

  

   }

  }

  g2d.dispose();

  RenderedImage rendImage = bufferedImage;


  File file = new File("C:\\Users\\User\\Desktop\\noise.png");

  ImageIO.write(rendImage, "png", file);

  

}



The output is what should be, just that it has some smoothing applied and the individuals pixels are not crisply defined.


Tagged: