e creation VolatileImage vImg = createVolatileImage(w, h); // rendering to the image void renderOffscreen() { do { if (vImg.validate(getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) { // old vImg doesn't work with new GraphicsConfig; re-create it vImg = createVolatileImage(w, h); } Graphics2D g = vImg.createGraphics(); // // miscellaneous rendering commands... // g.dispose(); } while (vImg.contentsLost()); } // copying from the image (here, gScreen is the Graphics // object for the onscreen window) do { int returnCode = vImg.validate(getGraphicsConfiguration()); if (returnCode == VolatileImage.IMAGE_RESTORED) { // Contents need to be restored renderOffscreen(); // restore contents } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) { // old vImg doesn't work with new GraphicsConfig; re-create it vImg = createVolatileImage(w, h); renderOffscreen(); } gScreen.drawImage(vImg, 0, 0, this); } while (vImg.contentsLost());
Note that this class subclasses from the {@link Image} class, whichincludes methods that take an {@link ImageObserver} parameter forasynchronous notifications as information is received from a potential {@link ImageProducer}. Since this VolatileImage
is not loaded from an asynchronous source, the various methods that take an ImageObserver
parameter will behave as if the data has already been obtained from the ImageProducer
. Specifically, this means that the return values from such methods will never indicate that the information is not yet available and the ImageObserver
used in such methods will never need to be recorded for an asynchronous callback notification.
@since 1.4