Managed Image creation

I create Managed Image via the GraphicsConfiguration.createCompatibleImage()
but i concerned if my code to create managed images is robust enough:


GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();

Is this a good way to acquire a GC to create Managed Images with or I have to enumarate devices and stick with the gcs currently used by the device (is so hou can acquire the gc currently used?).

My app is passive-rendered and windowed.

The fastest way to acquire accelerated sprite images is to load an image via ImageIO (a good way to load image with alpha channels without too much hassle) and then blit the Buffered Image I obtain in a Managed BufferedImage?

This method works but is really slow!

Component has the getGraphicsConfiguration() method.

Also, enumerating GraphicsDevices/GraphicsConfigs is rather expensive, so you should avoid it during your app startup if you care about startup time.

Thanks.

I was concerned about startup time but I was writing a class to manage animations & frames (it’s not a component) and I want it independent from the GUI (I ditched the old code that got the GC from the JFrame of the application) so we can use it on startup (before even creating the GUI or other visual components).

[quote]Thanks.

I was concerned about startup time but I was writing a class to manage animations & frames (it’s not a component) and I want it independent from the GUI (I ditched the old code that got the GC from the JFrame of the application) so we can use it on startup (before even creating the GUI or other visual components).
[/quote]
hmm, whether you can do that or not, depends on how exactly the underlying code works.

Is the GraphicsConfiguration returned from a Component always the same?

for example, if you change resolution, bitdepth, or drag a Frame from 1 monitor to another, is the GraphicsConfiguration of the Frame different? (or does it return different managed Images?)

If you create a managed image from a GraphicsConfiguration obtained from GraphicsDevice [1]
and then render it to a Graphics context obtained from a Component visible on GraphicsDevice [2], will the Image still be managed?
will the rendering be corrupt?
(or will the VM crash? ;P)

This is the way I should phrase my first question :stuck_out_tongue:

I checked a couple of examples/literacy/common practices here & there and using Local and Default devices is a common solution (even if is awesomely slow).

Expecially if what you want is only having an hardware accelerated image.

My concerns about dual display just holds (maybe I should check on hardware at University)…

The fact that BufferedImages will be always managed (even when created with new) is just corridor-talk or is confirmed for 1.5?

[quote] The fact that BufferedImages will be always managed (even when created with new) is just corridor-talk or is confirmed for 1.5?
[/quote]
BufferedImages are managed in 1.5.

Great! ;D

On the BufferedImage note, here’s a link to a short article that discusses just that, and a few other Java2D notes coming in 1.5.

http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html