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
-
Method Summary
Modifier and TypeMethodDescriptionget
(int idx) Retrieves one of the snapshotsint
getDelay()
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 snapshotsvoid
setDelay
(int delay) The delay between images in ms.int
size()
Retrieves the number of snapshots takenvoid
snapshot()
This method should be called every time you want a snapshot of the canvas to be taken.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 gifnum
timesdelay
seconds.boolean
Writes the image to a file, if this method fails it will returnfalse
and the exception will be saved.static void
write
(String path, int delay, BufferedImage... imgs) Creates a newgif
from an array ofBufferedImage
.
-
Constructor Details
-
Gif
Creates a new Gif object.- Parameters:
canvas
- the canvas from which to create the images- Throws:
IllegalArgumentException
- ifcanvas
isnull
- 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
null
if the index is out of bounds.
-
get
Retrieves one of the snapshots- Parameters:
idx
- index of th image- Returns:
- snapshot or
null
if 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 gifnum
timesdelay
seconds.- Parameters:
num
- number of snapshots- Throws:
InvalidArgumentException
- ifnum
is less than 1- See Also:
-
write
Writes the image to a file, if this method fails it will returnfalse
and the exception will be saved.- Parameters:
path
-String
representing the path and name of the file- Returns:
true
id thegif
was correctly written andfalse
if something goes wrong.- Throws:
IllegalArgumentException
- ifpath
isnull
- See Also:
-
getLastException
Retrieves the last exception in case such exception exists.
This method will always returnnull
beforewrite(String)
is called for the first time.- Returns:
- the exception or
null
if none exists. - See Also:
-
write
public static void write(String path, int delay, BufferedImage... imgs) throws IllegalArgumentException, IOException Creates a newgif
from an array ofBufferedImage
.- Parameters:
path
- The path in which to save thegif
delay
- The delay between frames in hundredths of a secondimgs
- Array of images- Throws:
IllegalArgumentException
- ifpath
isnull
IOException
- if something goes wrong when saving the image
-