LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

AnimationGlobalLoopプロパティ








アニメーション画像のためにグローバルループ数を示している値を取得または設定します。
構文
public int AnimationGlobalLoop {get; set;}
'Declaration
 
Public Property AnimationGlobalLoop As Integer
'Usage
 
Dim instance As RasterImage
Dim value As Integer
 
instance.AnimationGlobalLoop = value
 
value = instance.AnimationGlobalLoop
public int AnimationGlobalLoop {get; set;}
@property (nonatomic, assign) NSInteger animationGlobalLoop
public int getAnimationGlobalLoop()
public void setAnimationGlobalLoop(int value)
            
 <br/>get_AnimationGlobalLoop();<br/>set_AnimationGlobalLoop(value);<br/>Object.defineProperty('AnimationGlobalLoop'); 
public:
property int AnimationGlobalLoop {
   int get();
   void set (    int value);
}

属性値

アニメーション画像のためにグローバルループ数を示す整数値。以下は、有効値です:
意味
-1 ルーピングでない。これはデフォルト値です、そして、それはこのimageがアニメーション化されないことを意味します。たとえば、これは複数ページのTIFファイルによる場合です。
0 連続ルーピング。アニメーションは、無期限に同じことを繰り返さなければなりません。
<0 Nルーピング。アニメーションは、N回、同じことを繰り返さなければなりません。
解説

AnimationGlobalLoopの値が-1でないならば、imageはアニメーションを持っているためにみなされます、そして、imageは1つ以上のフレーム(PageCountは1より大きいです)を持っています。

このプロパティの値が変更されるとき、ChangedイベントはRasterImageChangedFlagsをRasterImageChangedFlags.AnimationPropertiesに設定して発生します。

詳細については、「アニメーションの実装」を参照してください。

サンプル

このサンプルは、4つの角に移動しているフレーム番号を示すアニメーションGIFファイルを作成します

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.Drawing

' WIN32 API
Const LOGPIXELSY As Integer = 90
<DllImport("gdi32")> _
Shared Function GetDeviceCaps(ByVal hdc As IntPtr, ByVal nIndex As Integer) As Integer
End Function

<DllImport("kernel32")> _
Shared Function MulDiv(ByVal nNumber As Integer, ByVal nNumerator As Integer, ByVal nDenominator As Integer) As Integer
End Function

Sub AnimatedGIFExample()
   ' The GIF file will contain 4 frames
   Const frameCount As Integer = 4

   ' Each frame is 128 by 128 pixels (the GIF file will have double that size)
   Const frameWidth As Integer = 128
   Const frameHeight As Integer = 128

   ' Background colors
   Dim backColor() As RasterColor = _
   { _
      New RasterColor(&HFF, &H0, &H0), _
      New RasterColor(&H0, &HFF, &H0), _
      New RasterColor(&H0, &H0, &HFF), _
      New RasterColor(&HFF, &HFF, &H0) _
   }

   ' Foreground colors
   Dim foreColor() As RasterColor = _
   { _
      New RasterColor(&HFF, &HFF, &H0), _
      New RasterColor(&HFF, &H0, &H0), _
      New RasterColor(&H0, &HFF, &H0), _
      New RasterColor(&HFF, &H0, &H0) _
   }

   ' Delay in milliseconds
   Dim delay() As Integer = _
   { _
      1000, _
      1000, _
      1000, _
      1000 _
   }

   ' Left and top, we want the frames to move to each corner
   Dim offset() As LeadPoint = _
   { _
      New LeadPoint(0, 0), _
      New LeadPoint(frameWidth, 0), _
      New LeadPoint(frameWidth, frameHeight), _
      New LeadPoint(0, frameHeight) _
   }

   Dim disposalMethod() As RasterImageAnimationDisposalMethod = _
   { _
      RasterImageAnimationDisposalMethod.RestoreBackground, _
      RasterImageAnimationDisposalMethod.RestoreBackground, _
      RasterImageAnimationDisposalMethod.RestoreBackground, _
      RasterImageAnimationDisposalMethod.RestoreBackground _
   }

   Dim backgroundColor As RasterColor = RasterColor.FromKnownColor(RasterKnownColor.Yellow)

   Dim image As RasterImage = Nothing
   Dim myFont As Font = Nothing
   Dim myStringFormat As StringFormat = Nothing

   ' Create the frames
   For frame As Integer = 0 To frameCount - 1
      Dim frameImage As New RasterImage( _
         RasterMemoryFlags.Conventional, _
         frameWidth, _
         frameHeight, _
         24, _
         RasterByteOrder.Bgr, _
         RasterViewPerspective.BottomLeft, _
         Nothing, _
         IntPtr.Zero, _
         0)

      ' Set the frame properties
      frameImage.AnimationDelay = delay(frame)
      frameImage.AnimationOffset = offset(frame)
      frameImage.AnimationDisposalMethod = disposalMethod(frame)

      ' Background is white
      frameImage.AnimationBackground = backgroundColor

      ' Draw the number of the frame on its surface
      Dim hdc As IntPtr = RasterImagePainter.CreateLeadDC(frameImage)
      Dim g As Graphics = Graphics.FromHdc(hdc)
      Dim rc As New Rectangle(0, 0, frameWidth, frameHeight)

      Dim brush As New SolidBrush(RasterColorConverter.ToColor(backColor(frame)))
      g.FillRectangle(brush, rc)
      brush.Dispose()

      If (myFont Is Nothing) Then
         Dim fontHeight As Integer = MulDiv(72, GetDeviceCaps(hdc, LOGPIXELSY), 72)
         myFont = New Font("Consolas", fontHeight)

         myStringFormat = New StringFormat()
         myStringFormat.Alignment = StringAlignment.Center
         myStringFormat.LineAlignment = StringAlignment.Center
      End If

      Dim str As String = String.Format("{0}", frame + 1)

      brush = New SolidBrush(RasterColorConverter.ToColor(foreColor(frame)))
      g.DrawString(str, myFont, brush, rc, myStringFormat)
      brush.Dispose()

      g.Dispose()
      RasterImagePainter.DeleteLeadDC(hdc)

      If (image Is Nothing) Then
         image = frameImage
      Else
         image.AddPage(frameImage)
      End If
   Next

   myFont.Dispose()
   myStringFormat.Dispose()

   ' Setup the global image properties
   image.AnimationGlobalSize = New LeadSize(frameWidth * 2, frameHeight * 2)
   image.AnimationGlobalLoop = 0
   image.AnimationGlobalBackground = backgroundColor

   ' Convert this image to 8 bits/pixel
   Dim cmd As New ColorResolutionCommand( _
      ColorResolutionCommandMode.AllPages, _
      8, _
      RasterByteOrder.Rgb, _
      RasterDitheringMethod.None, _
      ColorResolutionCommandPaletteFlags.Optimized, _
      Nothing)
   cmd.Run(image)

   Dim codecs As New RasterCodecs()

   ' Setup the GIF save options
   Dim animationPalette() As RasterColor = image.GetPalette()
   codecs.Options.Gif.Save.SetAnimationPalette(animationPalette)
   codecs.Options.Gif.Save.UseAnimationPalette = True

   ' The GIF Animation width & height, loop and background are
   ' pulled automatically from the image

   ' Save the file
   Dim fileName As String = Path.Combine(LEAD_VARS.ImagesDir, "AnimatedGifFile.gif")
   codecs.Save(image, fileName, RasterImageFormat.Gif, 8, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)

   image.Dispose()

   codecs.Dispose()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.Drawing;

// WIN32 API
const int LOGPIXELSY = 90;
[DllImport("gdi32")]
extern static int GetDeviceCaps(IntPtr hdc, int nIndex);

[DllImport("kernel32")]
extern static int MulDiv(int nNumber, int nNumerator, int nDenominator);

      
public void AnimatedGIFExample()
{
   // The GIF file will contain 4 frames
   const int frameCount = 4;

   // Each frame is 128 by 128 pixels (the GIF file will have double that size)
   const int frameWidth = 128;
   const int frameHeight = 128;

   // Background colors
   RasterColor[] backColor =
   {
      new RasterColor(0xFF, 0x00, 0x00),
      new RasterColor(0x00, 0xFF, 0x00),
      new RasterColor(0x00, 0x00, 0xFF),
      new RasterColor(0xFF, 0xFF, 0x00)
   };

   // Foreground colors
   RasterColor[] foreColor =
   {
      new RasterColor(0xFF, 0xFF, 0x00),
      new RasterColor(0xFF, 0x00, 0x00),
      new RasterColor(0x00, 0xFF, 0x00),
      new RasterColor(0xFF, 0x00, 0x00)
   };

   // Delay in milliseconds
   int[] delay =
   {
      1000,
      1000,
      1000,
      1000
   };

   // Left and top, we want the frames to move to each corner
   LeadPoint[] offset =
   {
      new LeadPoint(0, 0),
      new LeadPoint(frameWidth, 0),
      new LeadPoint(frameWidth, frameHeight),
      new LeadPoint(0, frameHeight),
   };

   RasterImageAnimationDisposalMethod[] disposalMethod =
   {
      RasterImageAnimationDisposalMethod.RestoreBackground,
      RasterImageAnimationDisposalMethod.RestoreBackground,
      RasterImageAnimationDisposalMethod.RestoreBackground,
      RasterImageAnimationDisposalMethod.RestoreBackground
   };

   RasterColor backgroundColor = RasterColor.FromKnownColor(RasterKnownColor.Yellow);

   RasterImage image = null;
   Font font = null;
   StringFormat stringFormat = null;

   // Create the frames
   for(int frame = 0; frame < frameCount; frame++)
   {
      RasterImage frameImage = new RasterImage(
         RasterMemoryFlags.Conventional,
         frameWidth,
         frameHeight,
         24,
         RasterByteOrder.Bgr,
         RasterViewPerspective.BottomLeft,
         null,
         IntPtr.Zero,
         0);

      // Set the frame properties
      frameImage.AnimationDelay = delay[frame];
      frameImage.AnimationOffset = offset[frame];
      frameImage.AnimationDisposalMethod = disposalMethod[frame];

      // Background is white
      frameImage.AnimationBackground = backgroundColor;

      // Draw the number of the frame on its surface
      IntPtr hdc = RasterImagePainter.CreateLeadDC(frameImage);
      Graphics g = Graphics.FromHdc(hdc);
      Rectangle rc = new Rectangle(0, 0, frameWidth, frameHeight);

      Brush brush = new SolidBrush(RasterColorConverter.ToColor(backColor[frame]));
      g.FillRectangle(brush, rc);
      brush.Dispose();

      if(font == null)
      {
         int fontHeight = MulDiv(72, GetDeviceCaps(hdc, LOGPIXELSY), 72);
         font = new Font("Consolas", fontHeight);

         stringFormat = new StringFormat();
         stringFormat.Alignment = StringAlignment.Center;
         stringFormat.LineAlignment = StringAlignment.Center;
      }

      string str = string.Format("{0}", frame + 1);

      brush = new SolidBrush(RasterColorConverter.ToColor(foreColor[frame]));
      g.DrawString(str, font, brush, rc, stringFormat);
      brush.Dispose();

      g.Dispose();
      RasterImagePainter.DeleteLeadDC(hdc);

      if (image == null)
         image = frameImage;
      else
         image.AddPage(frameImage);
   }

   font.Dispose();
   stringFormat.Dispose();

   // Setup the global image properties
   image.AnimationGlobalSize = new LeadSize(frameWidth * 2, frameHeight * 2);
   image.AnimationGlobalLoop = 0;
   image.AnimationGlobalBackground = backgroundColor;

   // Convert this image to 8 bits/pixel
   ColorResolutionCommand cmd = new ColorResolutionCommand(
      ColorResolutionCommandMode.AllPages,
      8,
      RasterByteOrder.Rgb,
      RasterDitheringMethod.None,
      ColorResolutionCommandPaletteFlags.Optimized,
      null);
   cmd.Run(image);

   RasterCodecs codecs = new RasterCodecs();

   // Setup the GIF save options
   RasterColor[] animationPalette = image.GetPalette();
   codecs.Options.Gif.Save.SetAnimationPalette(animationPalette);
   codecs.Options.Gif.Save.UseAnimationPalette = true;

   // The GIF Animation width & height, loop and background are
   // pulled automatically from the image

   // Save the file
   string fileName = Path.Combine(ImagesPath.Path, "AnimatedGifFile.gif");
   codecs.Save(image, fileName, RasterImageFormat.Gif, 8, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);

   image.Dispose();

   codecs.Dispose();
}
必要条件

ターゲットプラットホーム

参照

参照

RasterImageクラス
RasterImageメンバ
AnimationWaitUserInputプロパティ
AnimationOffsetプロパティ
AnimationDelayプロパティ
AnimationBackgroundプロパティ
AnimationDisposalMethodプロパティ
AnimationGlobalSizeプロパティ
AnimationGlobalBackgroundプロパティ
RasterImageAnimatorクラス
アニメーションの実装