Java 2D Drawing Optimal Performance

A synthesis of the answers to this post, the answers to Consty’s, and my own research:

What works:

  • Use GraphicsConfiguration.createCompatibleImage to create images compatible with what you’re drawing on. This is absolutely essential!
  • Use double-buffered drawing via Canvas.createBufferStrategy.
  • Use -Dsun.java2d.opengl=True where available to speed up drawing.
  • Avoid using transforms for scaling. Instead, cache scaled versions of the images you are going to use.
  • Avoid translucent images! Bitmasked images are fine, but translucency is very expensive in Java2D.

In my tests, using these methods, I got a speed increase of 10x – 15x, making proper Java 2D graphics a possibility.

Leave a Comment