0

I am using Java Canvas and have a draw method, which is called about 20 times a second. It iterates through an array of images and draws a scaledInstance of them depending on window size:

g.drawImage(img.getScaledInstance(
                (short)Math.round(rect.width * yVector),
                (short)Math.round(rect.height * yVector),
                Image.SCALE_SMOOTH),
        (short)Math.round(rect.x * xVector),
        (short)Math.round(rect.y * yVector), null);

Performance is really bad. I am using a buffer strategy and this is how the images, which are BufferedImage, are declared:

try {
    image = ImageIO.read(new File("resources/drawable/" + src));
    img = (BufferedImage)image.getImage();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Christoph Bühler
  • 2,795
  • 2
  • 28
  • 43

1 Answers1

0

The performance issues came from getScaledInstance. It scaled the image 20 times/second, which is not performant. Our application has now fixed positions and sizes, but runs with a very stable, high fps rate.

Christoph Bühler
  • 2,795
  • 2
  • 28
  • 43