Java Reference
In-Depth Information
You can ask the
MediaTracker
for its status at any time using the method
status(int ID
,
boolean load)
, which returns an integer made by
or
-ing together the values shown in
ages that haven't yet been started. A related method,
statusAll()
, returns the inclusive
or
of any flags applying to images that have started loading.
Table 12-1. MediaTracker status values
Flag
Meaning
Downloading of at least one item was aborted.
ABORTED
COMPLETE
Downloading of all items completed without error.
Something went wrong while downloading at least one item.
ERRORED
Downloading is ongoing.
LOADING
You can shorten the previous code by using the Swing
ImageIcon
class, which includes this
functionality. The
ImageIcon
class has several constructor forms, one of which takes just a
filename argument.
ImageIcon
uses a
MediaTracker
internally; you can ask for its status us-
ing the
ImageIcon
's
getImageLoadStatus()
method, which returns the same values as
Me-
diaTracker
's
statusAll()/statusID()
.
Reading and Writing Images with javax.imageio
Problem
You want to read a file, transform it, and write it back out.
Solution
Use the static
ImageIO
class from
javax.imageio
package; it provides static
read()
and
write()
methods.