Java The Complete Reference, Seventh Edition

(Greg DeLong) #1
Here is a simple example of animageUpdate( )method:

public boolean imageUpdate(Image img, int flags,
int x, int y, int w, int h) {
if ((flags & ALLBITS) == 0) {
System.out.println("Still processing the image.");
return true;
} else {
System.out.println("Done processing the image.");
return false;
}
}

Double Buffering


Not only are images useful for storing pictures, as we’ve just shown, but you can also use
them as offscreen drawing surfaces. This allows you to render any image, including text
and graphics, to an offscreen buffer that you can display at a later time. The advantage to
doing this is that the image is seen only when it is complete. Drawing a complicated image
could take several milliseconds or more, which can be seen by the user as flashing or flickering.

Chapter 25: Images 759


Flag Meaning
WIDTH Thewidthparameter is valid and contains the width of the image.
HEIGHT Theheightparameter is valid and contains the height of the image.
PROPERTIES The properties associated with the image can now be obtained using
imgObj.getProperty( ).
SOMEBITS More pixels needed to draw the image have been received. The parameters
left, top, width,andheightdefine the rectangle containing the new pixels.
FRAMEBITS A complete frame that is part of a multiframe image, which was previously
drawn, has been received. This frame can be displayed. Theleft, top, width,
andheightparameters are not used.
ALLBITS The image is now complete. Theleft, top, width,andheightparameters are
not used.
ERROR An error has occurred to an image that was being tracked asynchronously.
The image is incomplete and cannot be displayed. No further image
information will be received. TheABORTflag will also be set to indicate that
the image production was aborted.
ABORT An image that was being tracked asynchronously was aborted before it was
complete. However, if an error has not occurred, accessing any part of the
image’s data will restart the production of the image.

TABLE 25-1 Bit Flags of theimageUpdate( )flagsParameter
Free download pdf