Construct a GIF Image
The GifImage java class
is used to represent a gif image as a sequence of one or more frames
and to aggregate and encode some general gif image specific parameters including GIF image logic screen size, GIF file format version,
loop information and ASCII textual comments.
The GifImage class has the next constructors:
public GifImage();
public GifImage(int resizeStrategy);
public GifImage(int width, int height);
public GifImage(int width, int height, int resizeStrategy);
The first two constructors create GifImage with indefinite general gif image width and height -
these parameters will be taken from the first added frame.
Hint: You can always get the current gif image width/height using the next methods:
public int getCurrentLogicWidth()
public int getCurrentLogicHeight()
Resize Strategies
Gif4J PRO undertakes to control general image size (take into consideration all internal frames' size and their positions) using one of the predefined resize strategies:
Crop to Fit Image Size,
Scale to Fit Image Size and
Extend to Current.
First two strategies allows to fix the general gif image size (logical screen size).
The last extends logical screen size to fit all added gif frames.
Below examples demostrate all strategies (see examples/ResizeStrategies):

crop to fit image size (predefined size: 150x150)

scale to fit image size (predefined size: 150x150)

extend to current (extended size: 200x200)
GIF Image Looping
Animated gif images can have a Looping Application Extension Block that tells Encoder to loop the entire GIF file.
Based on the Gif89a specification you can set number of iterations between 0 and 65535 where 0 means indefinite (infinite) looping.
The next method should be used:
public void setLoopNumber(int number)
Note: By default a new GifImage doesn't contain a Looping Application Extension Block at all which is equal to 1 iteration.
To set, for example, infinite looping you should call gifImage.setLoopNumber(0).
Note: A lot of gif encoders and viewers (including Microsoft IE browser) ignore number of iterations more than 1
and iterate an animated gif image indefinitely.
Hint: You can set default delay time between frames. This delay is automatically applied to adding frames without delay parameter set.
The next method should be used:
public void setDefaultDelay(int delay)
Note: Any delay parameter is set in 1/100 (centiseconds) - value 100 means delay in 1 second.
Default delay between frames is set to 200 (2 seconds).
Add ASCII textual Comments to a GIF Image
The GIF Image Comment Extension contains textual information which
is not part of the actual graphics in the GIF Data Stream. It is suitable
for including comments about the graphics, credits, descriptions or any
other type of non-control and non-graphic data.
The next method should be used to add comments (please consult GifImage API for more info):
public void addComment(String comment);
|