ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Static Public Member Functions | List of all members
ImageResizer.Plugins.AnimatedGifs.GifCreator Class Reference

Provides methods for creating application and graphics blocks needed to write a animated Gif. More...

Static Public Member Functions

static void CreateAnimatedGif (List< string > gifFiles, int delay, string outputFile)
 
static byte[] CreateGraphicControlExtensionBlock (int delay)
 Written before each frame - specifies the frame's delay and the index of the transparent color (0) More...
 
static byte[] CreateGraphicControlExtensionBlock (int delay, byte transparentColorIndex)
 Written before each frame - specifies the frame's delay and the index of the transparent color More...
 
static byte[] CreateLoopBlock ()
 Creates a Loop Block (Netscape appliation extension) for infinite looping. Written after the last frame's image data More...
 
static byte[] CreateLoopBlock (int numberOfRepeatings)
 Creates a Loop block for the specified number of repeats. Written after the last frame's image data. Do NOT call this if numberOfRepeatings=1. IE and FF < 3 (incorrectly) loop infinitely when loops=1. Simply omit the extension in that case. More...
 

Detailed Description

Provides methods for creating application and graphics blocks needed to write a animated Gif.

Definition at line 22 of file GifCreator.cs.

Member Function Documentation

static byte [] ImageResizer.Plugins.AnimatedGifs.GifCreator.CreateGraphicControlExtensionBlock ( int  delay)
inlinestatic

Written before each frame - specifies the frame's delay and the index of the transparent color (0)

Parameters
delay
Returns

Definition at line 49 of file GifCreator.cs.

50  {
51  return CreateGraphicControlExtensionBlock(delay, 0);
52  }
static byte[] CreateGraphicControlExtensionBlock(int delay)
Written before each frame - specifies the frame&#39;s delay and the index of the transparent color (0) ...
Definition: GifCreator.cs:49
static byte [] ImageResizer.Plugins.AnimatedGifs.GifCreator.CreateGraphicControlExtensionBlock ( int  delay,
byte  transparentColorIndex 
)
inlinestatic

Written before each frame - specifies the frame's delay and the index of the transparent color

Parameters
delay
transparentColorIndex
Returns

Definition at line 59 of file GifCreator.cs.

60  {
61  /*320: 21 F9 04 Graphic Control Extension frame #1
62  323: 08 - no transparency
63  324: 09 00 - 0.09 sec duration
64  325: 00 - no transparent color
65  327: 00 - end
66  */
67  byte[] result = new byte[8];
68 
69 
70  result[0] = (byte)0x21; // Start ExtensionBlock
71  result[1] = (byte)0xF9; // GraphicControlExtension
72  result[2] = (byte)0x04; // Size of DataBlock (4)
73  // 1 enables transparency
74  // 8 clears to bgcolor after each frame.
75  // 25 (8 + 16) = restore to previous data (doesn't work in FF)
76  result[3] = 9; //Tansparent, clear to bgcolor (works good for transparent animaions
77 
78  // Split the delay into high- and lowbyte
79  result[4] = (byte)(delay % 256); //Duration - lsb
80  result[5] = (byte)(delay / 256); //msb
81  result[6] = transparentColorIndex; //Transparent color - only if transparency bit set.
82  result[7] = (byte)0x00; //end
83  return result;
84  }
static byte [] ImageResizer.Plugins.AnimatedGifs.GifCreator.CreateLoopBlock ( )
inlinestatic

Creates a Loop Block (Netscape appliation extension) for infinite looping. Written after the last frame's image data

Returns

Definition at line 89 of file GifCreator.cs.

90  { return CreateLoopBlock(0); }
static byte[] CreateLoopBlock()
Creates a Loop Block (Netscape appliation extension) for infinite looping. Written after the last fra...
Definition: GifCreator.cs:89
static byte [] ImageResizer.Plugins.AnimatedGifs.GifCreator.CreateLoopBlock ( int  numberOfRepeatings)
inlinestatic

Creates a Loop block for the specified number of repeats. Written after the last frame's image data. Do NOT call this if numberOfRepeatings=1. IE and FF < 3 (incorrectly) loop infinitely when loops=1. Simply omit the extension in that case.

Parameters
numberOfRepeatings
Returns

Definition at line 97 of file GifCreator.cs.

98  {
99  //http://www.let.rug.nl/kleiweg/gif/netscape.html
100  /*30D: 21 FF 0B Application Extension
101  310: 4E 45 54
102  53 43 41
103  50 45 32
104  2E 30 NETSCAPE2.0
105  31B: 03 01 - data follows
106  31D: FF FF - loop animation
107  31F: 00 - end
108  */
109  byte rep1 = (byte)(numberOfRepeatings % 256);
110  byte rep2 = (byte)(numberOfRepeatings / 256);
111  byte[] result = new byte[19];
112  result[0] = (byte)0x21; // Start ExtensionBlock
113  result[1] = (byte)0xFF; // ApplicationExtension
114  result[2] = (byte)0x0B; // Size of DataBlock (11) for NETSCAPE2.0)
115  result[3] = (byte)'N';
116  result[4] = (byte)'E';
117  result[5] = (byte)'T';
118  result[6] = (byte)'S';
119  result[7] = (byte)'C';
120  result[8] = (byte)'A';
121  result[9] = (byte)'P';
122  result[10] = (byte)'E';
123  result[11] = (byte)'2';
124  result[12] = (byte)'.';
125  result[13] = (byte)'0';
126  result[14] = (byte)0x03; // Size of Loop Block
127  result[15] = (byte)0x01; // Loop Indicator
128  result[16] = (byte)rep1; // Number of repetitions
129  result[17] = (byte)rep2; // 0 for endless loop
130  result[18] = (byte)0x00;
131  return result;
132  }

The documentation for this class was generated from the following file: