Jeremias or Thomas in particular, help!
I'm having trouble working out the relationships between the various
parts of Java2D, especially as regards the bits named above. At the end
of the day, the Graphics2D-GraphicsDevice combination is central to the
2D rendering process.
One instantiates a BufferedImage without specifically referring to any
elements of the GraphicsEnvironment, as for example in
PDFGraphicsConfiguration:
class PDFGraphicsConfiguration extends GraphicsConfiguration {
// We use this to get a good colormodel..
private static final BufferedImage BI_WITH_ALPHA =
new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
// We use this to get a good colormodel..
private static final BufferedImage BI_WITHOUT_ALPHA =
new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
...
}
From the instance of BufferedImage, we can get a Graphics2D instance:
BufferedImage bufim = new
BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2D = bufim.createGraphics();
From the Graphics2D, we get a GraphicsConfiguration and a
FontRenderContext:
GraphicsConfiguration grconf = g2D.getDeviceConfiguration();
FontRenderContext frc = g2D.getFontRenderContext();
The GraphicsConfiguration gets us back to the GraphicsDevice:
GraphicsDevice grdev = getDevice();
The GraphicsDevice won't take us back to its GraphicsEnvironment.
The implication of all of this, for me, is that a BufferedImage is not
created ex nihilo, but out of an understood context of GEnv, GDev and GConf.
GraphicsEnvironment provides a static method for retrieving the
underlying GraphicsEnvironment:
GraphicsEnvironment grenv =
GraphicsEnvironment.getLocalGraphicsEnvironment()
Given a GraphicsEnvironment and a BufferedImage, we can go the other way.
BufferedImage bufim = new
BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2D = grenv.createGraphics(bufim);
All of which seems redundant, given that we can get to a Graphics2d
directly from a BufferedImage. I assume, though, that this is the way
to introduce a "foreign" GraphicsEnvironment, e.g.,
PDFGraphicsEnvironment. Is this a fair assessment?
What puzzles me is the circularity of requiring a BufferedImage, with
its implicit dependency upon getLocalGraphicsEnvironment(), which seems
to be the only way to directly discover a GraphicsEnvironment. It's as
though there is no formal way to introduce your own GraphicsDevices,
apart from the sleight-of-hand of creating a parasite GEnv/GDev/GConf
through the reliance on BufferedImage.
What am I missing?
Peter