All Packages Class Hierarchy This Package Previous Next Index
Class com.kcmultimedia.gifcanvas.GIFParser
java.lang.Object
|
+----com.kcmultimedia.gifcanvas.GIFParser
- public class GIFParser
- extends Object
The GIFParser class encapsulates methods for parsing the frames and
control data for an animated (or static) GIF image. The class is
instantiated with a Component object (used to create images with
the Component's Toolkit.)
Next, a Vector of GIFFrame objects are
obtained using this class's parse(byte[]) method. The GIFFrame objects
contain individual images, absolute positioning, timing and disposal
data.
The overall width and height of the image are obtained next
using the getLogicalScreenWidth() and getLogicalScreenHeight() methods.
Finally, the number of iterations for looping are obtained using the
getIterations() method.
Static methods are provided for conveniently extracting the GIF's
byte array from either a File, URL, or generalized DataInputStream.
Sample code for extracting GIF data is shown below:
import java.util.*;
import java.awt.*;
import com.kcmultimedia.gifcanvas.*;
Vector gifFrames;
int overallWidth, overallHeight, doLoops;
public void sampleImageParse(Component aComponent,URL imageURL)
throws Exception
{
//Instantiate GIFParser with the Component and get
//the data we want...
GIFParser p = new GIFParser(aComponent);
gifFrames = p.parse(GIFParser.getBytes(imageURL));
overallWidth = p.getLogicalScreenWidth();
overallHeight = p.getLogicalScreenHeight();
doLoops = p.getIterations();
}
-
GIFParser(Component)
- Construct a GIFParser object
-
getBytes(DataInputStream)
- Get the GIF's bytes from a java.io.DataInputStream
-
getBytes(File)
- Get the GIF's bytes from a java.awt.File object
-
getBytes(URL)
- Get the GIF's bytes from a java.net.URL object
-
getIterations()
- Get the number of times to repeat the animation.
-
getLogicalScreenHeight()
- Get the overall height of the GIF image.
-
getLogicalScreenWidth()
- Get the overall width of the GIF image.
-
parse(byte[])
- Parse a GIF image, represented by an array of bytes returning a
Vector of GIFFrame objects.
GIFParser
public GIFParser(Component component)
- Construct a GIFParser object
- Parameters:
- component - a java.awt.Component object that is used to obtain the
Toolkit for creating images
parse
public Vector parse(byte b[]) throws Exception
- Parse a GIF image, represented by an array of bytes returning a
Vector of GIFFrame objects.
- Parameters:
- b - a array of bytes representing the GIF image
- Returns:
- a Vector of GIFFrame objects that contain the GIF data
- Throws: Exception
- thrown if the GIF file cannot be read or converted into an image.
- See Also:
- GIFFrame
getLogicalScreenWidth
public int getLogicalScreenWidth()
- Get the overall width of the GIF image.
- Returns:
- the overall width of the GIF in pixels
getLogicalScreenHeight
public int getLogicalScreenHeight()
- Get the overall height of the GIF image.
- Returns:
- the overall height of the GIF in pixels
getIterations
public int getIterations()
- Get the number of times to repeat the animation. Note
that zero (0) indicates infinite loop.
- Returns:
- the number of iterations for the animation loop.
getBytes
public static byte[] getBytes(File file) throws IOException
- Get the GIF's bytes from a java.awt.File object
- Parameters:
- file - the GIF image file
- Returns:
- a byte array containing the GIF data
- Throws: IOException
- thrown if an I/O Exception occurs.
getBytes
public static byte[] getBytes(URL url) throws IOException
- Get the GIF's bytes from a java.net.URL object
- Parameters:
- url - the GIF image's URL
- Returns:
- a byte array containing the GIF data
- Throws: IOException
- thrown if an I/O Exception occurs.
getBytes
public static byte[] getBytes(DataInputStream in) throws IOException
- Get the GIF's bytes from a java.io.DataInputStream
- Parameters:
- in - the DataInputStream representing the GIF data
- Returns:
- a byte array containing the GIF data
- Throws: IOException
- thrown if an I/O Exception occurs.
All Packages Class Hierarchy This Package Previous Next Index