public class Animation
extends java.lang.Object
Animation
class takes a series of Layer
s and
puts them in a single output graphic stream adding animation code for the
number of loops and the delay time and disposal method of the single patches.
What we do in this class is accept a series of layers, which will make up the single images. Currently layers are inserted into the animation in the succession of their addition. For each layer added, you may define the display time in 1/100th seconds and the disposal method used at the end of the display time.
In addition you may set global looping instruction, on how many times the sequence of images should be displayed. To disable setting the loop control value in the output file, set the global loop value to a negative value.
Properties
The Animation
class supports the following properties, which
are all backed by setter and getter methods :
loops | The number of loops to go through the animation. The default is not set byte the constructor or the setter is 0, which boils down to an endless loop. | |
defaultDisposal | The action the image decoder should take after the display time of an image has elapsed. This must be one of the defined DISPOSAL_* constants. The default if not set by a constructor or the setter is DISPOSAL_BACKGROUND. | |
backgroundColor | The background color of the animation. The default if not set by a constructor or the setter is to take the background color of the first image in the animation as the background color. |
Supported Image Format
Currently the Animation
class is solely implemented based on the
GIF image file format, whose general structure is described here. You will
also note, that the API of the Animation
class is based on the
functionality the GIF format offers for animated image files.
CompuServe Graphics Interchange Format (GIF)
The CompuServe Graphics Interchange Format (GIF) is a multi-image graphics format, which provides the capability for simple animations provided the image viewer is capable of interpreting the multi-image nature of the image file and the instructions for display.
Generally a GIF file is made up of the following structural elements :
For more details, look at the GIF89 Specification. Generally this page contains many interesting information on animated GIFs.
Modifier and Type | Field and Description |
---|---|
static int |
DISPOSAL_BACKGROUND
Restore to background color.
|
static int |
DISPOSAL_NO
Do not dispose.
|
static int |
DISPOSAL_NONE
No disposal specifed.
|
static int |
DISPOSAL_PREVIOUS
Restore to previous.
|
Constructor and Description |
---|
Animation()
Creates the
Animation object using the default values. |
Animation(int loops)
Creates the
Animation object using the given properties. |
Animation(int loops,
int defaultDisposal,
int bgColor)
Creates the
Animation object using the given properties. |
Modifier and Type | Method and Description |
---|---|
void |
addLayer(Layer layer,
int delay)
Add a layer for display during the indicated delay time after which the
image is disposed of using the default disposal method.
|
void |
addLayer(Layer layer,
int delay,
int disposal)
Add a layer for display during the indicated delay time after which the
image is disposed of using the disposal method.
|
int |
getBackgroundColor()
Returns the current desired background color, -1 if undefined.
|
int |
getDefaultDisposal()
Return the current default disposal method used for newly added
Layer s. |
int |
getLoops()
Returns the number of iterations through the images currently set.
|
Layer |
removeLayer(int idx)
Remove the layer with the given index from the
Animation . |
Layer |
removeLayer(Layer layer)
Removes the first layer (in chronological order) matching the given
layer from the animation.
|
void |
setBackgroundColor(int bgColor)
Sets the desired background color.
|
void |
setDefaultDisposal(int defaultDisposal)
Sets the default disposal method for newly added
Layer s. |
void |
setLoops(int loops)
Change the number of iterations through the images to the new value.
|
java.lang.String |
toString()
Convert the Animation to some string representation for intelligent
display.
|
void |
write(java.lang.String mimeType,
int numColors,
java.io.OutputStream outs)
Write the animation to the output indicated.
|
public static int DISPOSAL_NONE
public static int DISPOSAL_NO
public static int DISPOSAL_BACKGROUND
public static int DISPOSAL_PREVIOUS
public Animation(int loops, int defaultDisposal, int bgColor)
Animation
object using the given properties.loops
- Number of times the application should loop through the
images. Use a negative value to prevent looping at all.defaultDisposal
- default disposal method for images after the
delay time has elapsedbgColor
- The background color to set on the animated GIF. Only the
red, green and blue values are used, the alpha value is ignored
as GIF does not support alpha values.public Animation(int loops)
Animation
object using the given properties. The
background color is taken from the first image in the animation while the
default disposal method is set to DISPOSAL_BACKGROUND
.loops
- Number of times the application should loop through the
images. Use a negative value to prevent looping at all.public Animation()
Animation
object using the default values. The
background color is taken from the first image in the animation while the
default disposal method is set to DISPOSAL_BACKGROUND
. The
loop counter is initialized to 0, which means endless loop.public void setLoops(int loops)
loops
- Number of times the application should loop through the
images. Use a negative value to prevent looping at all or set
to 0 for endless looping.public int getLoops()
public void setDefaultDisposal(int defaultDisposal)
Layer
s.
This setting does not affect Layer
s already added to
the animation object !defaultDisposal
- The disposal method to use. This must be one of
DISPOSAL_* constants defined above.java.lang.IllegalArgumentException
- if the disposal value is illegal.DISPOSAL_NONE
,
DISPOSAL_NO
,
DISPOSAL_BACKGROUND
,
DISPOSAL_PREVIOUS
public int getDefaultDisposal()
Layer
s.public void setBackgroundColor(int bgColor)
bgColor
- The new background color to set. Only the
red, green and blue values are used, the alpha value is ignored
as GIF does not support alpha values.public int getBackgroundColor()
public void addLayer(Layer layer, int delay)
layer
- the Layer
object to adddelay
- the display time of the image in 1/100 sec.java.lang.NullPointerException
- if the layer is null
.public void addLayer(Layer layer, int delay, int disposal)
layer
- the Layer
object to adddelay
- the display time of the image in 1/100 sec.disposal
- the disposal method for the object. This must be one
of the predefined DISPOSAL_* constants.java.lang.NullPointerException
- if the layer is null
.java.lang.IllegalArgumentException
- if the disposal value is not one
of the predefined DISPOSAL_* constants.DISPOSAL_NONE
,
DISPOSAL_NO
,
DISPOSAL_BACKGROUND
,
DISPOSAL_PREVIOUS
public Layer removeLayer(int idx)
Animation
.idx
- index of the Layer
in the listAnimation
java.lang.IndexOutOfBoundsException
- if the index is less than zero or
bigger than the number of layers in the animation.java.lang.NullPointerException
- if no layer is present at the given
position.public Layer removeLayer(Layer layer)
removeLayer
.layer
- Layer
object to remove from the animationnull
if
the layer was not part of the animation.public void write(java.lang.String mimeType, int numColors, java.io.OutputStream outs) throws java.io.IOException
mimeType
- MIME type indicating the graphics output file format
to use. Currently only image/gif
is
supported.numColors
- The number of colors to generate in the animated GIF, if
not in the range [2 .. 256], 256 is taken as the
default.outs
- the OutputStream
used for outputjava.io.IOException
- got from called write
methodsjava.lang.IllegalArgumentException
- or if the mimeType
is
not image/gif
or if the
OutputStream
is null
.public java.lang.String toString()
toString
in class java.lang.Object
Animation
object.Copyright © 2010 - 2020 Adobe. All Rights Reserved