Example #1
0
 private void WriteGraphicControlBlock(sGif gif, TimeSpan frameDelay)
 {
     WriteShort(GraphicControlExtensionBlockIdentifier);             // Identifier
     WriteByte(GraphicControlExtensionBlockSize);                    // Block Size
     WriteByte(0x00);
     WriteShort(Convert.ToInt32(frameDelay.TotalMilliseconds / 10)); // Setting frame delay
     WriteByte(0);                                                   // Transparent color index
     WriteByte(0);                                                   // Terminator
 }
Example #2
0
 /// <summary>
 /// Adds a frame to this animation.
 /// </summary>
 /// <param name="img">The image to add</param>
 /// <param name="x">The positioning x offset this image should be displayed at.</param>
 /// <param name="y">The positioning y offset this image should be displayed at.</param>
 public void AddFrame(Image img)
 {
     using (var gifStream = new MemoryStream())
     {
         sGif gif = new sGif(img);
         if (_isFirstImage) // Steal the global color table info
         {
             InitHeader(gif);
         }
         WriteGraphicControlBlock(gif, FrameDelay);
         WriteImageBlock(gif, !_isFirstImage, 0, 0);
     }
     _isFirstImage = false;
 }
Example #3
0
 private void _AddFramePart(sFramePart part, bool firstPart)
 {
     using (var gifStream = new MemoryStream())
     {
         sGif gif = new sGif(part.Image, _isFirstImage);
         if (_isFirstImage) // Steal the global color table info
         {
             InitHeader(gif);
         }
         WriteGraphicControlBlock(gif, (firstPart ? FrameDelay : TimeSpan.FromSeconds(0)));
         WriteImageBlock(gif, !_isFirstImage, part.X, part.Y);
     }
     _isFirstImage = false;
 }
Example #4
0
        private void WriteImageBlock(sGif gif, bool includeColorTable, int x, int y)
        {
            WriteByte(ImageSeperator); // Separator
            WriteShort(x);             // Position X
            WriteShort(y);             // Position Y
            WriteShort(gif.CanvasWidth);
            WriteShort(gif.CanvasHeight);

            if (includeColorTable)                                      // If first frame, use global color table - else use local
            {
                WriteByte((((int)gif.PackedField & 0x70) >> 4) | 0x80); // Enabling local color table
                WriteByte(gif.ColorTable);
            }
            else
            {
                WriteByte(0); // Disabling local color table
            }
            WriteByte(gif.Data);
        }
Example #5
0
        private void InitHeader(sGif gif)
        {
            // File Header
            WriteString(FileType);
            WriteString(FileVersion);
            WriteShort(gif.CanvasWidth);  // Initial Logical Width
            WriteShort(gif.CanvasHeight); // Initial Logical Height
            WriteByte(gif.PackedField);   // Global Color Table Info
            WriteByte(0);                 // Background Color Index
            WriteByte(0);                 // Pixel aspect ratio
            WriteByte(gif.ColorTable);

            // App Extension Header
            WriteShort(ApplicationExtensionBlockIdentifier);
            WriteByte(ApplicationBlockSize);
            WriteString(ApplicationIdentification);
            WriteByte(3);  // Application block length
            WriteByte(1);
            WriteShort(0); // Repeat count for images.
            WriteByte(0);  // terminator
        }