Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
FrameRegion(Graphics,RasterRegionXForm,Int32) Method
See Also  Example
Leadtools Namespace > RasterImage Class > FrameRegion Method : FrameRegion(Graphics,RasterRegionXForm,Int32) Method



graphics
Graphics object where the image is displayed and where the frame is to appear.
xform
RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates.
frameIndex
Zero-index of the frame to display. Possible values are from 0 to MaxRegionFrameIndex. You can animate the region frame by cycling between these values.
Displays an outline of the image region in the given Graphics object.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub FrameRegion( _
   ByVal graphics As Graphics, _
   ByVal xform As RasterRegionXForm, _
   ByVal frameIndex As Integer _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterImage
Dim graphics As Graphics
Dim xform As RasterRegionXForm
Dim frameIndex As Integer
 
instance.FrameRegion(graphics, xform, frameIndex)
C# 
public void FrameRegion( 
   Graphics graphics,
   RasterRegionXForm xform,
   int frameIndex
)
C++/CLI 
public:
void FrameRegion( 
   Graphics graphics,
   RasterRegionXForm^ xform,
   int frameIndex
) 

Parameters

graphics
Graphics object where the image is displayed and where the frame is to appear.
xform
RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates.
frameIndex
Zero-index of the frame to display. Possible values are from 0 to MaxRegionFrameIndex. You can animate the region frame by cycling between these values.

Example

Visual BasicCopy Code
Public Sub FrameRegionExample()
   Dim f As FrameRegionForm = New FrameRegionForm()
   f.ShowDialog()
End Sub

Private Class FrameRegionForm : Inherits Form
   Private frameIndex As Integer
   Private image As RasterImage
   Private timer As System.Windows.Forms.Timer
   Private fillRegion As Boolean

   Public Sub New()
      ' Load the image
      RasterCodecs.Startup()
      Dim codecs As RasterCodecs = New RasterCodecs()

      Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
      image = codecs.Load(srcFileName)

      ' Add a region to the image
      Dim rc As Rectangle = New Rectangle(image.Width \ 3, image.Height \ 3, image.Width \ 3, image.Height \ 3)
      Dim xform As RasterRegionXForm = 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
      AddHandler timer.Tick, AddressOf timer_Tick
      timer.Start()
   End Sub

   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      ' Clean up
      If disposing Then
         timer.Dispose()
         image.Dispose()
         RasterCodecs.Shutdown()
      End If

      MyBase.Dispose(disposing)
   End Sub

   Protected Overrides Sub OnDoubleClick(ByVal e As EventArgs)
      fillRegion = Not fillRegion
      Invalidate()

      MyBase.OnDoubleClick(e)
   End Sub

   Private Function GetXForm(ByVal destRect As Rectangle) As RasterRegionXForm
      ' Calculate xform when the image is painted into 'destRect'
      Dim xform As RasterRegionXForm = 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
   End Function

   Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
      ' Draw the image fit and center on this form
      Dim destRect As Rectangle = RasterImage.CalculatePaintModeRectangle(image.ImageWidth, image.ImageHeight, ClientRectangle, RasterPaintSizeMode.Fit, RasterPaintAlignMode.Center, RasterPaintAlignMode.Center)
      image.Paint(e.Graphics, Rectangle.Empty, Rectangle.Empty, destRect, e.ClipRectangle, RasterPaintProperties.Default)

      If fillRegion Then
         Dim xform As RasterRegionXForm = GetXForm(destRect)
         image.FillRegion(e.Graphics, xform, New RasterColor(255, 0, 255))
      End If

      MyBase.OnPaint(e)
   End Sub

   Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
      ' Frame the image region
      Dim destRect As Rectangle = RasterImage.CalculatePaintModeRectangle(image.ImageWidth, image.ImageHeight, ClientRectangle, RasterPaintSizeMode.Fit, RasterPaintAlignMode.Center, RasterPaintAlignMode.Center)

      Dim xform As RasterRegionXForm = GetXForm(destRect)

      Dim g As Graphics = CreateGraphics()
      Try
         image.FrameRegion(g, xform, frameIndex)
      Finally
         CType(g, IDisposable).Dispose()
      End Try

      ' advance to next frame
      frameIndex += 1
      If frameIndex > RasterImage.MaxRegionFrameIndex Then
         frameIndex = 0
      End If
   End Sub
End Class
C#Copy Code
public void FrameRegionExample() 

   FrameRegionForm f = new FrameRegionForm(); 
   f.ShowDialog(); 

 
class FrameRegionForm : Form 

   int frameIndex; 
   RasterImage image; 
   System.Windows.Forms.Timer timer; 
   bool fillRegion; 
 
   public FrameRegionForm() 
   { 
      // Load the image 
      RasterCodecs.Startup(); 
      RasterCodecs codecs = new RasterCodecs(); 
 
      string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
      image = codecs.Load(srcFileName); 
 
      // Add a region to the image 
      Rectangle rc = new Rectangle(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) 
      { 
         timer.Dispose(); 
         image.Dispose(); 
         RasterCodecs.Shutdown(); 
      } 
 
      base.Dispose(disposing); 
   } 
 
   protected override void OnDoubleClick(EventArgs e) 
   { 
      fillRegion = !fillRegion; 
      Invalidate(); 
 
      base.OnDoubleClick(e); 
   } 
 
   RasterRegionXForm GetXForm(Rectangle 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 
      Rectangle destRect = RasterImage.CalculatePaintModeRectangle( 
         image.ImageWidth, 
         image.ImageHeight, 
         ClientRectangle, 
         RasterPaintSizeMode.Fit, 
         RasterPaintAlignMode.Center, 
         RasterPaintAlignMode.Center); 
      image.Paint(e.Graphics, Rectangle.Empty, Rectangle.Empty, destRect, e.ClipRectangle, RasterPaintProperties.Default); 
 
      if(fillRegion) 
      { 
         RasterRegionXForm xform = GetXForm(destRect); 
         image.FillRegion(e.Graphics, xform, new RasterColor(255, 0, 255)); 
      } 
 
      base.OnPaint(e); 
   } 
 
   void timer_Tick(object sender, EventArgs e) 
   { 
      // Frame the image region 
      Rectangle destRect = RasterImage.CalculatePaintModeRectangle( 
         image.ImageWidth, 
         image.ImageHeight, 
         ClientRectangle, 
         RasterPaintSizeMode.Fit, 
         RasterPaintAlignMode.Center, 
         RasterPaintAlignMode.Center); 
 
      RasterRegionXForm xform = GetXForm(destRect); 
 
      using(Graphics g = CreateGraphics()) 
         image.FrameRegion(g, xform, frameIndex); 
 
      // advance to next frame 
      frameIndex++; 
      if(frameIndex > RasterImage.MaxRegionFrameIndex) 
         frameIndex = 0; 
   } 
}

Remarks

If the region includes noncontiguous shapes, each shape is outlined. The outline, itself, is inside the region.

Before calling this method, create a RasterRegionXForm object and set its values, which LEADTOOLS uses to translate between device context coordinates and image coordinates.

This method is designed to produce an animated frame, which you can implement by calling the method with a timer event that cycles through the possible frame types.

For more information, refer to Creating a Region and Working with the Existing Region.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also