views:

486

answers:

1

I am creating a buffered image that is going to be a snapshot of a JComponent (via paint()) and rendered inside an ImageIcon. There are a large amount of types in the BufferedImage(int width, int height, int imageType) constructor, but which one should I use?

I am sure that any of them would work, but which ones are better than the others? And Why?

+1  A: 

See GraphicsConfiguration.createCompatibleImage(int, int) for a helper to create a BufferedImage of a "good" type among the many available types.

How to get your hands on a GraphicsConfiguration instance to make this call? It depends on where your code is executing. See the many methods for getting your hands on a GraphicsConfiguration via methods like getGraphicsConfiguration() or getDeviceConfiguration().

John M
If you only had a code snippet instead of a javadoc link you would so get the answer.
shemnon
be careful iterating over graphics configurations. depending on your hardware, some of those methods take several seconds the first time.
John Gardner
yes, what is X? No check mark with such unsure code snippets.
shemnon
I will have to live forever without the sweet, sweet feeling of this particular check mark. Oh, what might have been...
John M
No, you code snippit is still incomplete. WTF is x? People come here for cut and paste solutions, put one in the answer.
shemnon
and don't forget to fromat it properly by putting in four spaces in the front.
shemnon