Slick2D Image.getColor crash

Hi all! So now I making method which taking screen shot. This is what happens in that method:

if (takeScreenShot) {
			  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
	        Date date = new Date();
	        File folder = new File("screenshots/");

	        if(!folder.exists()) {
	        File screenshotFile = new File("screenshots/screenshot-" + format.format(date) + ".png");
	        Image screenshot= new Image(gc.getWidth(), gc.getHeight());
	        g.copyArea(screenshot, 0, 0);
	        ImageOut.write(screenshot, screenshotFile.toString(), false);
	        takeScreenShot = false;

But then it must take screenshot I getting this error:

java.lang.ArrayIndexOutOfBoundsException: 2097152
	at org.newdawn.slick.Image.getColor(
	at org.newdawn.slick.imageout.ImageIOWriter.saveImage(
	at org.newdawn.slick.imageout.ImageOut.write(
	at org.newdawn.slick.imageout.ImageOut.write(
	at game.states.MenuState.screenshotChecker(
	at game.states.MenuState.render(
	at org.newdawn.slick.state.StateBasedGame.render(
	at org.newdawn.slick.GameContainer.updateAndRender(
	at org.newdawn.slick.AppGameContainer.gameLoop(
	at org.newdawn.slick.AppGameContainer.start(
	at game.Main.launch(
	at game.Launcher.main(

Why Image.getColor fails? ??? Can someone explain that or help me? :slight_smile: Thanks in advance :wink:

Are you flipping the image at any point?

As I can see, no.

Then I after “g.copyArea(screenshot, 0, 0);” add “screenshot= screenshot.getFlippedCopy(false, true);” it works but I getting flipped image :frowning:
I dont want flip it, but without it I getting error >:(

Someone can me help solve it??

Finally I solved it, I made only small change, instead of:

Image screenshot = new Image(gc.getWidth(), gc.getHeight());

I write:

Image screenshot = new Image(gc.getWidth() - 1, gc.getHeight() - 1);

And now it works perfectly :stuck_out_tongue:

A quick google revealed this:

BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "png", new File("/screenshot.png"));

Thanks anyway :wink: