←Select platform

ClearUpdateRectangle Method

Summary
Clears the update rectangle used for an animation playback, leaving an empty rectangle.
Syntax
C#
VB
C++
public void ClearUpdateRectangle() 
Public Sub ClearUpdateRectangle()  
public: 
void ClearUpdateRectangle();  
Example

This example uses ClearUpdateRectangle to avoid painting odd numbered frames

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Drawing; 
 
 
[Ignore()] 
public void RasterImageAnimatorClearUpdateRectangleExample(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.PostRender: 
				index = animator.Index; 
				if ((index % 2) != 0) 
					animator.ClearUpdateRectangle(); 
 
				// 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:\LEADTOOLS21\Resources\Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.Drawing 
 
Sub RasterImageAnimatorClearUpdateRectangleExample(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.PostRender 
            index = animator.Index 
            If ((index Mod 2) <> 0) Then 
               animator.ClearUpdateRectangle() 
            End If 
 
            ' 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:\LEADTOOLS21\Resources\Images" 
End Class 
Requirements

Target Platforms

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.