LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

Index Property

Example 





Gets or sets the index of the current frame during animation playback. .NET support WinRT support
Syntax
public int Index {get; set;}
'Declaration
 
Public Property Index As Integer
'Usage
 
Dim instance As RasterImageAnimator
Dim value As Integer
 
instance.Index = value
 
value = instance.Index
public int Index {get; set;}
 get_Index();
set_Index(value);
public:
property int Index {
   int get();
   void set (    int value);
}

Property Value

An integer value that indicates the index of the current frame during animation playback.
Remarks

You can use the Index property to skip frames during a playback if required.

Example
 
Sub RasterImageAnimatorIndexExample(ByVal panel As Panel)
      ' Initialize the RasterCodecs object
      Dim codecs As New RasterCodecs()
      ' Load the animated GIF file
      Dim fileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Eye.gif")
      Dim animatedImage As RasterImage = codecs.Load(fileName)

      ' Create the target image, we want it to be in the animated image size
      Dim targetImage As New RasterImage( _
         RasterMemoryFlags.Conventional, _
         animatedImage.AnimationGlobalSize.Width, _
         animatedImage.AnimationGlobalSize.Height, _
         animatedImage.BitsPerPixel, _
         animatedImage.Order, _
         animatedImage.ViewPerspective, _
         Nothing, _
         IntPtr.Zero, _
         0)

      ' Copy the palette from the animated image to this newly created image
      animatedImage.CopyPaletteTo(targetImage)

      ' Create the RasterImageAnimator object
      Dim animator As New RasterImageAnimator(targetImage, animatedImage)

      ' Animate it

      ' Use GDI+ paint engine to support transparent colors
      Dim props As RasterPaintProperties = RasterPaintProperties.Default
      props.PaintEngine = RasterPaintEngine.GdiPlus

      Dim g As Graphics = panel.CreateGraphics()

      Dim state As RasterImageAnimatorState
      Do
         Dim srcRect As New LeadRect(0, 0, targetImage.ImageWidth, targetImage.ImageHeight)
         Dim updateRect As LeadRect
         Dim destRect As LeadRect
         Dim index As Integer

         state = animator.Process()

         Select Case (state)
            Case RasterImageAnimatorState.WaitDelay, _
               RasterImageAnimatorState.WaitInputDelay, _
               RasterImageAnimatorState.Render
               'Continue processing

            Case RasterImageAnimatorState.WaitInput
               ' In case the animated image has the "wait for user input" flags,
               ' cancel the waiting
               animator.CancelWait()

            Case RasterImageAnimatorState.PreRender
               index = animator.Index
               index = index + 1
               animator.Index = index

            Case RasterImageAnimatorState.PostRender
               ' Get the area in the target image that has changed
               updateRect = animator.GetUpdateRectangle(True)

               ' Paint it
               destRect = New LeadRect(0, 0, targetImage.ImageWidth, targetImage.ImageHeight)

               RasterImagePainter.Paint(targetImage, g, srcRect, updateRect, destRect, destRect, props)
         End Select
      Loop While (state <> RasterImageAnimatorState.End)

      g.Dispose()

      animator.Dispose()

      targetImage.Dispose()
      animatedImage.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 RasterImageAnimatorIndexExample(Panel panel)
   {
      // Initialize the RasterCodecs object
      RasterCodecs codecs = new RasterCodecs();

      // Load the animated GIF file
      string fileName = Path.Combine(LEAD_VARS.ImagesDir, "Eye.gif");
      RasterImage animatedImage = codecs.Load(fileName);

      // Create the target image, we want it to be in the animated image size
      RasterImage targetImage = new RasterImage(
         RasterMemoryFlags.Conventional,
         animatedImage.AnimationGlobalSize.Width,
         animatedImage.AnimationGlobalSize.Height,
         animatedImage.BitsPerPixel,
         animatedImage.Order,
         animatedImage.ViewPerspective,
         null,
         IntPtr.Zero,
         0);

      // Copy the palette from the animated image to this newly created image
      animatedImage.CopyPaletteTo(targetImage);

      // Create the RasterImageAnimator object
      RasterImageAnimator animator = new RasterImageAnimator(targetImage, animatedImage);

      // Animate it

      // Use GDI+ paint engine to support transparent colors
      RasterPaintProperties props = RasterPaintProperties.Default;
      props.PaintEngine = RasterPaintEngine.GdiPlus;

      Graphics g = panel.CreateGraphics();

      RasterImageAnimatorState state;
      do
      {
         LeadRect srcRect = new LeadRect(0, 0, targetImage.ImageWidth, targetImage.ImageHeight);
         LeadRect updateRect;
         LeadRect destRect;
         int index;

         state = animator.Process();

         switch(state)
         {
            case RasterImageAnimatorState.WaitDelay:
            case RasterImageAnimatorState.WaitInputDelay:
            case RasterImageAnimatorState.Render:
               // Continue processing
               break;

            case RasterImageAnimatorState.WaitInput:
               // In case the animated image has the "wait for user input" flags,
               // cancel the waiting
               animator.CancelWait();
               break;

            case RasterImageAnimatorState.PreRender:
               index = animator.Index;
               index++;
               animator.Index = index;
               break;

            case RasterImageAnimatorState.PostRender:
               // Get the area in the target image that has changed
               updateRect = animator.GetUpdateRectangle(true);

               // Paint it
               destRect = new LeadRect(0, 0, targetImage.ImageWidth, targetImage.ImageHeight);

               RasterImagePainter.Paint(targetImage, g, srcRect, updateRect, destRect, destRect, props);
               break;

            default:
               break;
         }
      }
      while(state != RasterImageAnimatorState.End);

      g.Dispose();

      animator.Dispose();

      targetImage.Dispose();
      animatedImage.Dispose();

      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
[TestMethod]
public async Task RasterImageAnimatorIndexExample()
{
   // Initialize the RasterCodecs object
   RasterCodecs codecs = new RasterCodecs();
   // Load the animated GIF file
   string srcFileName = @"Assets\eye.gif";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage animatedImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // Create the target image, we want it to be in the animated image size
   RasterImage targetImage = new RasterImage(
      RasterMemoryFlags.Conventional,
      animatedImage.AnimationGlobalSize.Width,
      animatedImage.AnimationGlobalSize.Height,
      animatedImage.BitsPerPixel,
      animatedImage.Order,
      animatedImage.ViewPerspective,
      null);

   // Copy the palette from the animated image to this newly created image
   animatedImage.CopyPaletteTo(targetImage);

   // Create the RasterImageAnimator object
   RasterImageAnimator animator = new RasterImageAnimator(targetImage, animatedImage);

   // Animate it

   RasterImageAnimatorState state;
   int loopCount = 0;
   do
   {
      LeadRect srcRect = LeadRectHelper.Create(0, 0, targetImage.ImageWidth, targetImage.ImageHeight);
      LeadRect updateRect;
      LeadRect destRect;
      int index;

      state = animator.Process();

      switch (state)
      {
         case RasterImageAnimatorState.WaitDelay:
         case RasterImageAnimatorState.WaitInputDelay:
         case RasterImageAnimatorState.Render:
            // Continue processing
            loopCount++;
            Debug.WriteLine(string.Format("loopCount: {0}\n", loopCount));
            break;

         case RasterImageAnimatorState.WaitInput:
            // In case the animated image has the "wait for user input" flags,
            // cancel the waiting
            animator.CancelWait();
            break;

         case RasterImageAnimatorState.PreRender:
            index = animator.Index;
            index++;
            //animator.Index = index;
            break;

         case RasterImageAnimatorState.PostRender:
            // Get the area in the target image that has changed
            updateRect = animator.GetUpdateRectangle(true);

            // Paint it
            destRect = LeadRectHelper.Create(0, 0, targetImage.ImageWidth, targetImage.ImageHeight);

            // Render the image here, for example, set the frame to a viewer control
            // rasterImageViewer.Image = targetImage;
            break;

         default:
            break;
      }
   }
   while (state != RasterImageAnimatorState.End);

   animator.Dispose();

   targetImage.Dispose();
   animatedImage.Dispose();

   codecs.Dispose();
}
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

RasterImageAnimator Class
RasterImageAnimator Members

 

 


Products | Support | Contact Us | Copyright Notices

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