A Quick Snippet for Drawing Images in Java

Java does not have the best built-in tools in the world for drawing images, but it’s still useful for many purposes. Below is just a snippet on getting started drawing in Java. For more information on what’s available see the Java Graphics class reference.

BufferedImage i = new BufferedImage(500, 500,BufferedImage.TYPE_INT_RGB);
Graphics g=i.createGraphics();
g.setColor(Color.BLUE);
g.drawLine(0, 0, 500, 500);
g.drawString("This is a test", 20,20);
ImageIO.write(i,"jpg",new File("test.jpg");

Leave a Reply