I’m working on a game that needs the image-drawing to be accellerated to run in a reasonable amount of time. Most of the time, it works fine. But when I take a screenshot (for storing in a file to display in the load game screen), it slows way down. Presumably, what happens is that it accelerates the Images used to create the screenshot instead of the regular Images.
Is there some way to make it so that a BufferedImage will not be accellerated? I tried the setAccelerationPriority method, but it didn’t work (a priority of 0 should prevent acceleration). I also tried flushing the image acceleration data after I’m done changing it, but that didn’t work either.
Here’s my code for taking the screenshot:
public BufferedImage takeScreenshot(final int screenshotWidth,
final int screenshotHeight, final boolean bIncludeStatusBar)
{
//take a screenshot
BufferedImage fullScreenImage = new BufferedImage(
GuiUtil.getMainFrameWidth(), GuiUtil.getMainFrameHeight(),
BufferedImage.TYPE_INT_RGB);
fullScreenImage.setAccelerationPriority(0);
paint(fullScreenImage.createGraphics());
//figure out how much of the screen to use
int heightOfStartingImageToUse = bIncludeStatusBar ? GuiUtil.getMainFrameHeight() :
yStatusBar;
//create the resized image
BufferedImage screenshotImage = new BufferedImage(screenshotWidth,
screenshotHeight, BufferedImage.TYPE_INT_RGB);
screenshotImage.setAccelerationPriority(0);
Graphics2D g2 = screenshotImage.createGraphics();
g2.drawImage(fullScreenImage, 0, 0, screenshotWidth, screenshotHeight,
0, 0, GuiUtil.getMainFrameWidth(), yStatusBar, null);
g2.dispose();
//flush all the screenshot image optimization data to avoid a slowdown when drawing
//the screen
fullScreenImage.flush();
screenshotImage.flush();
return screenshotImage;
} //end takeScreenshot
It occurs to me that just making the BufferedImages type ARGB might do the trick because translucent Images aren’t accelerated. However, I would like some better solution.