|
|
How to create animated images
Using ShotGraph you can create animated GIFs on-line as well as static ones.
To create an animation you should use the special object called animation track.
This object is created every time you create the "shotgraph.image"
object. Just after creation the animation track is empty.
To create an animation, you should do the following:
- Create a "shotgraph.image" object.
- Make the necessary drawings.
- Call TrackAdd function.
- Repeat steps 2 and 3 as many times as necessary
- If you want to loop your animation, call TrackLoop
function (registered version only).
- Call TrackPlay function to get
animated file or binary stream data.
The animation track use your working image size and palette are defined
in the time of first calling TrackAdd.
You can not create an animated image from empty track.
Note. ShotGraph is not a specialized GIF animator. The animation
features are only additional cababilities of this software. The main goal
of this program is the making of static images on the fly for your
WWW service.
Hint.
To get fully colorized animations with your custom graphics included
with necessary colors, you can use local clipboard, instead of direct
drawing the image in the main working space and sending the ready frame directly
to the animation track. You can use this method if the summary color palette
is too big or indefined.
The necessary steps are shown below:
- Create the clipboard of necessary size by calling InitClipboard function.
The clipboard area size should be enough to include all animation frames
together.
- Make the clipboard working area active, by calling SelectClipboard function.
- Place all frames on the clipboard area.
- Call either WebPalette or BuildPalette method
to calculate and rebuild the new image palette.
- Copy frame by frame from clipboard using Copy method to main working image space and
sequentally add them to the animation track.
- Call TrackPlay method to create the animation.
Example
As example, let's join two GIF images together to create the animation.
There are our two files, frame1.gif and frame2.gif. The picture size
of every file is 400x50 pixels.
 frame1.gif |
 frame2.gif |
As you see, the summary palette size of both files is bigger then
maximal available (256), so we will need recalculate the resulting
palette on the clipboard. The script producing the animation is quite
short, here it is:
set obj=CreateObject("shotgraph.image")
xsize=400
ysize=50
obj.CreateImage xsize,ysize,256
obj.InitClipboard xsize,ysize*2
obj.SelectClipboard True
obj.ReadImage "frame1.gif",pal1,0,0
obj.ReadImage "frame2.gif",pal2,0,ysize
obj.BuildPalette 0
obj.Copy 0,0,xsize,ysize,0,0,"SRCCOPY"
obj.TrackAdd -1,0,0,0,0,xsize,ysize,50
obj.Copy 0,0,xsize,ysize,0,ysize,"SRCCOPY"
obj.TrackAdd -1,0,0,0,0,xsize,ysize,50
obj.TrackLoop 0
obj.TrackPlay "frames12.gif"
The result of script working is the file frames12.gif:
|