Java - image creation

I am currently working on a game in Java and am trying to create a background without using any image files. The image consists of a square divided into 4 triangles, each of which has a different color.

If someone could tell me that someone used Graphics2D and then saved it to BufferedImage , that would be great.

+4
source share
1 answer

I recommend:

  • First create a BufferedImage using a constructor that takes three Ints :. In width, height, and type BufferedImage, BufferedImage.TYPE_INT_ARGB will probably work well, and width and height will probably be Constants in the program
  • You would retrieve the Graphics2D object from the BufferedImage by calling its createGraphics() method.
  • Then draw the Graphics object using the drawXXX(...) methods, of which you have many choices.
  • To change the color, simply call setColor(Color c) on your Graphics / Graphics2D object.
  • When drawing, be sure to delete your Graphics object using the dispose() method.
  • Edit according to Adrian Blackburn, check out the BufferedImage Study Guide as part of the standard Oracle Java tutorials.
+7
source

All Articles