This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,208 Users
  • 2,269,776 Discussions
  • 7,916,824 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: