1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| private static BufferedImage toCompatibleImage(BufferedImage image) { GraphicsConfiguration gfx_config = DisplayManager.getGraphicsConfiguration(); if (image.getColorModel().equals(gfx_config.getColorModel())) { image.setAccelerationPriority(1.0f); return image; } BufferedImage new_image = gfx_config.createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency()); Graphics2D g2d = (Graphics2D) new_image.getGraphics(); g2d.drawImage(image, 0, 0, null); g2d.dispose(); new_image.setAccelerationPriority(1.0f); return new_image; } |
Note: DisplayManager.getGraphicsConfiguration(); is from my engine, you have to get your GraphicsConfiguration however else
So I have used this in the past; when loading an image from ImageIO I would pass it through this method.
I removed it and wrote this comment back then:
"// Eats double RAM with no CPU performance improvement @ drawing whatsoever."Also takes longer to load obviously.
I didn't test it thoroughly; but it didn't show any improvement, so I haven't used it ever in Java2D