jbcl.util Package
java.lang.Object +----com.borland.jbcl.util.SerializableImage
Variables Constructors Properties Methods
Implements Serializable
SerializableImage
is a class that enables serialization of java.awt.Image
objects.
Use this class when you need to save an image object into a serialized stream. When the image object is set, this class extracts the pixel information using a PixelGrabber
, and the image is serialized as pixel data. When the image is deserialized, or retrieved, this class constructs a new MemoryImageSource
object out of the saved pixel data.
The following is an example of reading and writing an Image
data member from a class that implements java.io.Serializable
.
// Image object marked as transient private transient Image image; // Custom serialization support - save to stream private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeObject(SerializableImage.create(image)); } // Custom serialization support - load from stream private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); image = ((SerializableImage)s.readObject()).getImage(); }
protected transient Image image
protected int[] imageData
protected int imageHeight
protected int imageWidth
public SerializableImage()Constructs a
SerializableImage
object with no associated java.awt.Image
object.
public SerializableImage(Image image)Constructs a
SerializableImage
object with the passed java.awt.Image
object.
Parameters:
image
java.awt.Image
object.
public Image getImage() public void setImage(Image image)The
image
property defines the java.awt.Image
object that is to be serialized with this class.
public static final SerializableImage create(Image source)If the
Image
specified with the source
parameter exists, this method attempts to create a SerializableImage
by calling the SerializableImage
constructor, passing to it the source Image
. create
returns the SerializableImage
.