Package com.dkt.graphics.utils
Class Gif
java.lang.Object
com.dkt.graphics.utils.Gif
The purpose of this class is to create animated GIFs from a series of canvas
snapshots
- Since:
- 0.1.10
- Author:
- Federico Vera <[email protected]>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget(int idx) Retrieves one of the snapshotsintgetDelay()Retrieves the delay between images in ms.
The default value is 100ms.Retrieves the last exception in case such exception exists.remove(int idx) Removes on of the snapshotsvoidsetDelay(int delay) The delay between images in ms.intsize()Retrieves the number of snapshots takenvoidsnapshot()This method should be called every time you want a snapshot of the canvas to be taken.voidsnapshot(int num) This method callssnapshot()a given number of times, which results in (besides an increase in size) the image staying on the gifnumtimesdelayseconds.booleanWrites the image to a file, if this method fails it will returnfalseand the exception will be saved.static voidwrite(String path, int delay, BufferedImage... imgs) Creates a newgiffrom an array ofBufferedImage.
-
Constructor Details
-
Gif
Creates a new Gif object.- Parameters:
canvas- the canvas from which to create the images- Throws:
IllegalArgumentException- ifcanvasisnull- See Also:
-
-
Method Details
-
size
public int size()Retrieves the number of snapshots taken- Returns:
- number of snapshots
-
remove
Removes on of the snapshots- Parameters:
idx- index of the snapshot- Returns:
- the image that was removed or
nullif the index is out of bounds.
-
get
Retrieves one of the snapshots- Parameters:
idx- index of th image- Returns:
- snapshot or
nullif the index is out of bounds
-
getDelay
public int getDelay()Retrieves the delay between images in ms.
The default value is 100ms.- Returns:
- delay between images
- See Also:
-
setDelay
public void setDelay(int delay) The delay between images in ms. Note that since the GIF specification sets the delay in hundredths of a second the number of ms is actually divided by ten.- Parameters:
delay- delay in ms- See Also:
-
snapshot
public void snapshot()This method should be called every time you want a snapshot of the canvas to be taken. You must take at least 1 in order for the save method to do something.- See Also:
-
snapshot
public void snapshot(int num) This method callssnapshot()a given number of times, which results in (besides an increase in size) the image staying on the gifnumtimesdelayseconds.- Parameters:
num- number of snapshots- Throws:
InvalidArgumentException- ifnumis less than 1- See Also:
-
write
Writes the image to a file, if this method fails it will returnfalseand the exception will be saved.- Parameters:
path-Stringrepresenting the path and name of the file- Returns:
trueid thegifwas correctly written andfalseif something goes wrong.- Throws:
IllegalArgumentException- ifpathisnull- See Also:
-
getLastException
Retrieves the last exception in case such exception exists.
This method will always returnnullbeforewrite(String)is called for the first time.- Returns:
- the exception or
nullif none exists. - See Also:
-
write
public static void write(String path, int delay, BufferedImage... imgs) throws IllegalArgumentException, IOException Creates a newgiffrom an array ofBufferedImage.- Parameters:
path- The path in which to save thegifdelay- The delay between frames in hundredths of a secondimgs- Array of images- Throws:
IllegalArgumentException- ifpathisnullIOException- if something goes wrong when saving the image
-