Java2D Performance Issues?

I think I found a solution by researching and putting bits and pieces together from too many Google searches Here it is, comments and all: private BufferedImage toCompatibleImage(BufferedImage image) { // obtain the current system graphical settings GraphicsConfiguration gfx_config = GraphicsEnvironment. GetLocalGraphicsEnvironment(). GetDefaultScreenDevice().

GetDefaultConfiguration(); /* * if image is already compatible and optimized for current system * settings, simply return it */ if (image.getColorModel(). Equals(gfx_config.getColorModel())) return image; // image is not optimized, so create a new image that is BufferedImage new_image = gfx_config. CreateCompatibleImage( image.getWidth(), image.getHeight(), image.getTransparency()); // get the graphics context of the new image to draw the old image on Graphics2D g2d = (Graphics2D) new_image.getGraphics(); // actually draw the image and dispose of context no longer needed g2d.

DrawImage(image, 0, 0, null); g2d.dispose(); // return the new optimized image return new_image; } In my previous post, GraphicsConfiguration was what held the information needed to create optimized images on a system. It seems to work pretty well, but I would have thought Java would automatically do this for you. Obviously you can't get too comfortable with Java.

:) I guess I ended up answering my own question. Oh well, hopefully it'll help some of you I've seen trying to make use of Java for 2D games.

I think I found a solution by researching and putting bits and pieces together from too many Google searches. Here it is, comments and all: private BufferedImage toCompatibleImage(BufferedImage image) { // obtain the current system graphical settings GraphicsConfiguration gfx_config = GraphicsEnvironment. GetLocalGraphicsEnvironment().

GetDefaultScreenDevice(). GetDefaultConfiguration(); /* * if image is already compatible and optimized for current system * settings, simply return it */ if (image.getColorModel(). Equals(gfx_config.getColorModel())) return image; // image is not optimized, so create a new image that is BufferedImage new_image = gfx_config.

CreateCompatibleImage( image.getWidth(), image.getHeight(), image.getTransparency()); // get the graphics context of the new image to draw the old image on Graphics2D g2d = (Graphics2D) new_image.getGraphics(); // actually draw the image and dispose of context no longer needed g2d. DrawImage(image, 0, 0, null); g2d.dispose(); // return the new optimized image return new_image; } In my previous post, GraphicsConfiguration was what held the information needed to create optimized images on a system. It seems to work pretty well, but I would have thought Java would automatically do this for you.

Obviously you can't get too comfortable with Java. :) I guess I ended up answering my own question. Oh well, hopefully it'll help some of you I've seen trying to make use of Java for 2D games.

From what I remember when I was thinking about doing graphics programming in Java, the built in libraries are slow. I was advised on GameDev. Net that anyone doing anything serious would have to use something like jogl.

Well since the largest performance penalty is actually calling drawImage(), I'd consider 450 calls with 700 FPS pretty good. I'd have to write the same thing in jogl to see if there's a significant difference, but great progress has been made with Java2D in recent versions of Java. – Consty Oct 13 '08 at 7:18.

I'm having performance oddities with Java2D. I know of the sun. Opengl VM parameter to enable 3D acceleration for 2D, but even using that has some weird issues.

Bmp format, Image 2 = A . 120 FPS using .

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions