I'm writing a widget that does some caching to avoid unecessary calls to Shape.draw on a bunch of shapes at every repaint.
I've tried to do something like this (scala code):
private val buffer = new BufferedImage(width, height, /* (1) */)
...
override def paintComponent(Graphics2D g) = {
if (hasChanged) {
val bg = buffer.getGraphics.asInstanceOf[Graphics2D]
bg.draw(/* ... */)
buffer.flush
}
g.drawImage(buffer, null /* (2) */, 0, 0)
}
I'm not sure what to put in (1)
and (2)
. null
for (2) seems to work (I want no transformation). But for (1)
I have no idea which image type to chose. Is there a way of asking for the "right" one at runtime?