Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java awt Graphics2D crisp pixel edges

MikeyJYAug 12 2021

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.
noise.png (15.23 KB)

Comments

Post Details

Added on Aug 12 2021
0 comments
246 views