←Select platform

MaxRegionFrameIndex Field

Summary
Gets the maximum region frame index.
Syntax
C#
C++/CLI
Python
public static readonly int MaxRegionFrameIndex 
public: 
static readonly int MaxRegionFrameIndex 
MaxRegionFrameIndex (RasterImagePainter) 

Field Value

The maximum region frame index.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
 
 
public void FrameRegionExample() 
{ 
   FrameRegionForm f = new FrameRegionForm(); 
   f.ShowDialog(); 
} 
 
class FrameRegionForm : Form 
{ 
   private int frameIndex; 
   private RasterImage image; 
   private System.Windows.Forms.Timer timer; 
   private bool fillRegion; 
 
   public FrameRegionForm() 
   { 
      // Load the image 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
         image = codecs.Load(srcFileName); 
      } 
 
      // Add a region to the image 
      LeadRect rc = new LeadRect(image.Width / 3, image.Height / 3, image.Width / 3, image.Height / 3); 
      RasterRegionXForm xform = new RasterRegionXForm(); 
      xform.ViewPerspective = RasterViewPerspective.TopLeft; 
      image.AddEllipseToRegion(xform, rc, RasterRegionCombineMode.Set); 
 
      // initialize the frame index 
      frameIndex = 0; 
 
      fillRegion = true; 
 
      Text = "Double click to enable/disable filling the region"; 
 
      // Create the timer 
      timer = new System.Windows.Forms.Timer(); 
      timer.Interval = 100; 
      timer.Tick += new EventHandler(timer_Tick); 
      timer.Start(); 
   } 
 
   protected override void Dispose(bool disposing) 
   { 
      // Clean up 
      if (disposing) 
      { 
         if (timer != null) 
         { 
            timer.Dispose(); 
         } 
 
         if (image != null) 
         { 
            image.Dispose(); 
         } 
 
      } 
 
      base.Dispose(disposing); 
   } 
 
   protected override void OnDoubleClick(EventArgs e) 
   { 
      fillRegion = !fillRegion; 
      Invalidate(); 
 
      base.OnDoubleClick(e); 
   } 
 
   private RasterRegionXForm GetXForm(LeadRect destRect) 
   { 
      // Calculate xform when the image is painted into 'destRect' 
      RasterRegionXForm xform = new RasterRegionXForm(); 
      xform.ViewPerspective = RasterViewPerspective.TopLeft; 
      xform.XOffset = destRect.Left; 
      xform.YOffset = destRect.Top; 
      xform.XScalarDenominator = image.Width; 
      xform.XScalarNumerator = destRect.Width; 
      xform.YScalarDenominator = image.Height; 
      xform.YScalarNumerator = destRect.Height; 
 
      return xform; 
   } 
 
   protected override void OnPaint(PaintEventArgs e) 
   { 
      // Draw the image fit and center on this form 
      LeadRect destRect = LeadRect.FromLTRB(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Bottom); 
      destRect = RasterImage.CalculatePaintModeRectangle( 
          image.ImageWidth, 
          image.ImageHeight, 
          destRect, 
          RasterPaintSizeMode.Fit, 
          RasterPaintAlignMode.Center, 
          RasterPaintAlignMode.Center); 
 
      LeadRect clipRect = LeadRect.FromLTRB(e.ClipRectangle.Left, e.ClipRectangle.Top, e.ClipRectangle.Right, e.ClipRectangle.Bottom); 
      RasterImagePainter.Paint(image, e.Graphics, LeadRect.Empty, LeadRect.Empty, destRect, clipRect, RasterPaintProperties.Default); 
 
      if (fillRegion) 
      { 
         RasterRegionXForm xform = GetXForm(destRect); 
         RasterImagePainter.FillRegion(image, e.Graphics, xform, new RasterColor(255, 0, 255)); 
      } 
 
      base.OnPaint(e); 
   } 
 
   private void timer_Tick(object sender, EventArgs e) 
   { 
      // Frame the image region 
      LeadRect destRect = LeadRect.FromLTRB(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Bottom); 
 
      destRect = RasterImage.CalculatePaintModeRectangle( 
         image.ImageWidth, 
         image.ImageHeight, 
         destRect, 
         RasterPaintSizeMode.Fit, 
         RasterPaintAlignMode.Center, 
         RasterPaintAlignMode.Center); 
 
      RasterRegionXForm xform = GetXForm(destRect); 
 
      using (Graphics g = CreateGraphics()) 
      { 
         RasterImagePainter.FrameRegion(image, g, xform, frameIndex); 
      } 
 
      // advance to next frame 
      frameIndex++; 
      if (frameIndex > RasterImagePainter.MaxRegionFrameIndex) 
      { 
         frameIndex = 0; 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Remarks

When painting an image region using FrameRegion(RasterImage,Graphics,RasterRegionXForm,Int32), you can animate the region frame by cycling through the region frames for 0 to MaxRegionFrameIndex.

For more information refer to RasterImage and GDI/GDI+.

Requirements

Target Platforms

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

Leadtools.Drawing Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.