LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

CodecsGifOptions Class

Example 





Members 
Provides extra options for loading and saving GIF images. .NET support WinRT support Silverlight support
Object Model
CodecsGifOptions ClassCodecsGifLoadOptions ClassCodecsGifSaveOptions Class
Syntax
public class CodecsGifOptions 
'Declaration
 
Public Class CodecsGifOptions 
'Usage
 
Dim instance As CodecsGifOptions
public sealed class CodecsGifOptions 
function Leadtools.Codecs.CodecsGifOptions()
public ref class CodecsGifOptions 
Example
 
Public Sub CodecsGifOptionsExample()
      Dim codecs As RasterCodecs = New RasterCodecs()
      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "eye.gif")

      ' Get all Information about the Gif file that you want to load.
      Dim imageInfo As CodecsImageInfo = codecs.GetInformation(srcFileName, True)

      ' set the animation loop value. 
      If imageInfo.Gif.HasAnimationLoop Then
         codecs.Options.Gif.Load.AnimationLoop = imageInfo.Gif.AnimationLoop
         If imageInfo.Gif.AnimationLoop > 10 Then
            codecs.Options.Gif.Save.AnimationLoop = 10
         End If
      End If

      ' if this image that you want to load uses the Animation loop then use it in the save options.
      codecs.Options.Gif.Save.UseAnimationLoop = imageInfo.Gif.HasAnimationLoop

      ' if this image that you want to load uses the Animation Background then use it in the save options.
      If imageInfo.Gif.HasAnimationBackground Then
         codecs.Options.Gif.Save.AnimationBackground = imageInfo.Gif.AnimationBackground
      End If

      ' if this image that you want to load uses the Animation Palette then use it in the save options.
      If imageInfo.Gif.HasAnimationPalette Then
         codecs.Options.Gif.Save.SetAnimationPalette(imageInfo.Gif.GetAnimationPalette())
      End If

      codecs.Options.Gif.Save.UseAnimationPalette = imageInfo.Gif.HasAnimationPalette

      ' if this image that you want to load uses the Intrlaced option, then use it otherwise don't use it.
      codecs.Options.Gif.Save.Interlaced = imageInfo.Gif.IsInterlaced

      codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth
      codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight

      Dim srcImage As RasterImage = codecs.Load(srcFileName)

      codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "gif1.gif"), RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite)

      'change some save options and save the image in a new file.
      codecs.Options.Gif.Save.UseAnimationLoop = True
      codecs.Options.Gif.Save.AnimationLoop = 1
      codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth + 100
      codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight + 100

      'Saving the image after the Gif setting.
      codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "gif2.gif"), RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite)

      ' Clean up
      srcImage.Dispose()
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void CodecsGifOptionsExample()
     {
         RasterCodecs codecs = new RasterCodecs();
         string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "eye.gif");

         // Get all Information about the Gif file that you want to load.
         CodecsImageInfo imageInfo = codecs.GetInformation(srcFileName, true);

         // set the animation loop value. 
         if (imageInfo.Gif.HasAnimationLoop)
         {
             codecs.Options.Gif.Load.AnimationLoop = imageInfo.Gif.AnimationLoop;
             if (imageInfo.Gif.AnimationLoop > 10)
                 codecs.Options.Gif.Save.AnimationLoop = 10;
         }

         // if this image that you want to load uses the Animation loop then use it in the save options.
         codecs.Options.Gif.Save.UseAnimationLoop = imageInfo.Gif.HasAnimationLoop;

         // if this image that you want to load uses the Animation Background then use it in the save options.
         if (imageInfo.Gif.HasAnimationBackground)
             codecs.Options.Gif.Save.AnimationBackground = imageInfo.Gif.AnimationBackground;

         // if this image that you want to load uses the Animation Palette then use it in the save options.
         if (imageInfo.Gif.HasAnimationPalette)
             codecs.Options.Gif.Save.SetAnimationPalette(imageInfo.Gif.GetAnimationPalette());

         codecs.Options.Gif.Save.UseAnimationPalette = imageInfo.Gif.HasAnimationPalette;

         // if this image that you want to load uses the Intrlaced option, then use it otherwise don't use it.
         codecs.Options.Gif.Save.Interlaced = imageInfo.Gif.IsInterlaced;

         codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth;
         codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight;

         RasterImage srcImage = codecs.Load(srcFileName);

         codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "gif1.gif"), RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite);

         //change some save options and save the image in a new file.
         codecs.Options.Gif.Save.UseAnimationLoop = true;
         codecs.Options.Gif.Save.AnimationLoop = 1;
         codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth + 100;
         codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight + 100;

         //Saving the image after the Gif setting.
         codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "gif2.gif"), RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite);

         // Clean up
         srcImage.Dispose();
         codecs.Dispose();
     }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
CodecsOptionsExamples.prototype.CodecsGifOptionsExample = function ( )
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();
         var srcFileName = "Assets\\eye.gif";
         var imageInfo;
         var srcImage;
         // Get all Information about the Gif file that you want to load.
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.getInformationAsync(LeadStreamFactory.create(loadFile), true, 1)
         })
         .then(function (imgInfo) {
            imageInfo = imgInfo;

            // set the animation loop value. 
            if (imageInfo.gif.hasAnimationLoop) {
               codecs.options.gif.load.animationLoop = imageInfo.gif.animationLoop;
               if (imageInfo.gif.animationLoop > 10)
                  codecs.options.gif.save.animationLoop = 10;
            }

            // if this image that you want to load uses the Animation loop then use it in the save options.
            codecs.options.gif.save.useAnimationLoop = imageInfo.gif.hasAnimationLoop;

            // if this image that you want to load uses the Animation Background then use it in the save options.
            if (imageInfo.gif.hasAnimationBackground)
               codecs.options.gif.save.animationBackground = imageInfo.gif.animationBackground;

            // if this image that you want to load uses the Animation Palette then use it in the save options.
            if (imageInfo.gif.hasAnimationPalette)
               codecs.options.gif.save.setAnimationPalette(imageInfo.gif.getAnimationPalette());

            codecs.options.gif.save.useAnimationPalette = imageInfo.gif.hasAnimationPalette;

            // if this image that you want to load uses the Intrlaced option, then use it otherwise don't use it.
            codecs.options.gif.save.interlaced = imageInfo.gif.isInterlaced;

            codecs.options.gif.save.animationWidth = imageInfo.gif.animationWidth;
            codecs.options.gif.save.animationHeight = imageInfo.gif.animationHeight;

            return Tools.AppInstallFolder().getFileAsync(srcFileName)
         })
         .then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (srcImg) {
            srcImage = srcImg;
            var destFileName = "gif1.gif";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.gif, srcImage.bitsPerPixel, 1, srcImage.pageCount, 1, CodecsSavePageMode.overwrite);

            //change some save options and save the image in a new file.
            codecs.options.gif.save.useAnimationLoop = true;
            codecs.options.gif.save.animationLoop = 1;
            codecs.options.gif.save.animationWidth = imageInfo.gif.animationWidth + 100;
            codecs.options.gif.save.animationHeight = imageInfo.gif.animationHeight + 100;

            //Saving the image after the Gif setting.
            destFileName = "gif2.gif";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            return codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.gif, srcImage.bitsPerPixel, 1, srcImage.pageCount, 1, CodecsSavePageMode.overwrite)
         })
         .then(function (saveFile) {

            // Clean up
            srcImage.close();
            codecs.close();
         });
      }
   }
}
[TestMethod]
public async Task CodecsGifOptionsExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\eye.gif";
   // Get all Information about the Gif file that you want to load.
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   CodecsImageInfo imageInfo = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), true, 1);

   // set the animation loop value. 
   if (imageInfo.Gif.HasAnimationLoop)
   {
      codecs.Options.Gif.Load.AnimationLoop = imageInfo.Gif.AnimationLoop;
      if (imageInfo.Gif.AnimationLoop > 10)
         codecs.Options.Gif.Save.AnimationLoop = 10;
   }

   // if this image that you want to load uses the Animation loop then use it in the save options.
   codecs.Options.Gif.Save.UseAnimationLoop = imageInfo.Gif.HasAnimationLoop;

   // if this image that you want to load uses the Animation Background then use it in the save options.
   if (imageInfo.Gif.HasAnimationBackground)
      codecs.Options.Gif.Save.AnimationBackground = imageInfo.Gif.AnimationBackground;

   // if this image that you want to load uses the Animation Palette then use it in the save options.
   if (imageInfo.Gif.HasAnimationPalette)
      codecs.Options.Gif.Save.SetAnimationPalette(imageInfo.Gif.GetAnimationPalette());

   codecs.Options.Gif.Save.UseAnimationPalette = imageInfo.Gif.HasAnimationPalette;

   // if this image that you want to load uses the Intrlaced option, then use it otherwise don't use it.
   codecs.Options.Gif.Save.Interlaced = imageInfo.Gif.IsInterlaced;

   codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth;
   codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight;

   loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   string destFileName = @"gif1.gif";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(srcImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite);

   //change some save options and save the image in a new file.
   codecs.Options.Gif.Save.UseAnimationLoop = true;
   codecs.Options.Gif.Save.AnimationLoop = 1;
   codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth + 100;
   codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight + 100;

   //Saving the image after the Gif setting.
   destFileName = @"gif2.gif";
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(srcImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite);

   // Clean up
   srcImage.Dispose();
   codecs.Dispose();
}
public void CodecsGifOptionsExample(Stream inStreamGif, Stream outStreamGif1, Stream outStreamGif2)
{
   RasterCodecs codecs = new RasterCodecs();
   // Get all Information about the Gif file that you want to load.
   CodecsImageInfo imageInfo = codecs.GetInformation(inStreamGif, true);

   // set the animation loop value. 
   if (imageInfo.Gif.HasAnimationLoop)
   {
      codecs.Options.Gif.Load.AnimationLoop = imageInfo.Gif.AnimationLoop;
      if (imageInfo.Gif.AnimationLoop > 10)
         codecs.Options.Gif.Save.AnimationLoop = 10;
   }

   // if this image that you want to load uses the Animation loop then use it in the save options.
   codecs.Options.Gif.Save.UseAnimationLoop = imageInfo.Gif.HasAnimationLoop;

   // if this image that you want to load uses the Animation Background then use it in the save options.
   if (imageInfo.Gif.HasAnimationBackground)
      codecs.Options.Gif.Save.AnimationBackground = imageInfo.Gif.AnimationBackground;

   // if this image that you want to load uses the Animation Palette then use it in the save options.
   if (imageInfo.Gif.HasAnimationPalette)
      codecs.Options.Gif.Save.SetAnimationPalette(imageInfo.Gif.GetAnimationPalette());

   codecs.Options.Gif.Save.UseAnimationPalette = imageInfo.Gif.HasAnimationPalette;

   // if this image that you want to load uses the Intrlaced option, then use it otherwise don't use it.
   codecs.Options.Gif.Save.Interlaced = imageInfo.Gif.IsInterlaced;

   codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth;
   codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight;

   RasterImage srcImage = codecs.Load(inStreamGif);

   codecs.Save(srcImage, outStreamGif1, RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite);

   //change some save options and save the image in a new file.
   codecs.Options.Gif.Save.UseAnimationLoop = true;
   codecs.Options.Gif.Save.AnimationLoop = 1;
   codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth + 100;
   codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight + 100;

   //Saving the image after the Gif setting.
   codecs.Save(srcImage, outStreamGif2, RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite);

   // Clean up
   srcImage.Dispose();
}
Public Sub CodecsGifOptionsExample(ByVal inStreamGif As Stream, ByVal outStreamGif1 As Stream, ByVal outStreamGif2 As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' Get all Information about the Gif file that you want to load.
   Dim imageInfo As CodecsImageInfo = codecs.GetInformation(inStreamGif, True)

   ' set the animation loop value. 
   If imageInfo.Gif.HasAnimationLoop Then
      codecs.Options.Gif.Load.AnimationLoop = imageInfo.Gif.AnimationLoop
      If imageInfo.Gif.AnimationLoop > 10 Then
         codecs.Options.Gif.Save.AnimationLoop = 10
      End If
   End If

   ' if this image that you want to load uses the Animation loop then use it in the save options.
   codecs.Options.Gif.Save.UseAnimationLoop = imageInfo.Gif.HasAnimationLoop

   ' if this image that you want to load uses the Animation Background then use it in the save options.
   If imageInfo.Gif.HasAnimationBackground Then
      codecs.Options.Gif.Save.AnimationBackground = imageInfo.Gif.AnimationBackground
   End If

   ' if this image that you want to load uses the Animation Palette then use it in the save options.
   If imageInfo.Gif.HasAnimationPalette Then
      codecs.Options.Gif.Save.SetAnimationPalette(imageInfo.Gif.GetAnimationPalette())
   End If

   codecs.Options.Gif.Save.UseAnimationPalette = imageInfo.Gif.HasAnimationPalette

   ' if this image that you want to load uses the Intrlaced option, then use it otherwise don't use it.
   codecs.Options.Gif.Save.Interlaced = imageInfo.Gif.IsInterlaced

   codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth
   codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight

   Dim srcImage As RasterImage = codecs.Load(inStreamGif)

   codecs.Save(srcImage, outStreamGif1, RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite)

   'change some save options and save the image in a new file.
   codecs.Options.Gif.Save.UseAnimationLoop = True
   codecs.Options.Gif.Save.AnimationLoop = 1
   codecs.Options.Gif.Save.AnimationWidth = imageInfo.Gif.AnimationWidth + 100
   codecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight + 100

   'Saving the image after the Gif setting.
   codecs.Save(srcImage, outStreamGif2, RasterImageFormat.Gif, srcImage.BitsPerPixel, 1, srcImage.PageCount, 1, CodecsSavePageMode.Overwrite)

   ' Clean up
   srcImage.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CodecsGifOptions Members
Leadtools.Codecs Namespace
Implementing GIF Features

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.