- image
- The source image.
- graphics
- System.Drawing.Graphics object where the image is displayed and where the frame is to appear.
- xform
- Leadtools.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.
Visual Basic (Declaration) | |
---|---|
Overloads Public Shared Sub FrameRegion( _ ByVal image As RasterImage, _ ByVal graphics As Graphics, _ ByVal xform As RasterRegionXForm, _ ByVal frameIndex As Integer _ ) |
Visual Basic (Usage) | Copy Code |
---|---|
Dim image As RasterImage Dim graphics As Graphics Dim xform As RasterRegionXForm Dim frameIndex As Integer RasterImagePainter.FrameRegion(image, graphics, xform, frameIndex) |
C# | |
---|---|
public static void FrameRegion( RasterImage image, Graphics graphics, RasterRegionXForm xform, int frameIndex ) |
C++/CLI | |
---|---|
public: static void FrameRegion( RasterImage^ image, Graphics^ graphics, RasterRegionXForm^ xform, int frameIndex ) |
Parameters
- image
- The source image.
- graphics
- System.Drawing.Graphics object where the image is displayed and where the frame is to appear.
- xform
- Leadtools.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.
Visual Basic | Copy Code |
---|---|
Public Sub FrameRegionExample() Dim f As New FrameRegionForm() f.ShowDialog() End Sub 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 Using codecs As New RasterCodecs() Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") image = codecs.Load(srcFileName) End Using ' Add a region to the image Dim rc As New LeadRect(image.Width \ 3, image.Height \ 3, image.Width \ 3, image.Height \ 3) Dim xform As 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 Overrides Sub Dispose(ByVal disposing As Boolean) ' Clean up If disposing Then If Not IsNothing(timer) Then timer.Dispose() End If If Not IsNothing(image) Then image.Dispose() End If 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 LeadRect) As RasterRegionXForm ' Calculate xform when the image is painted into 'destRect' Dim xform As 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 LeadRect = LeadRect.FromLTRB(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Bottom) destRect = RasterImage.CalculatePaintModeRectangle( _ image.ImageWidth, _ image.ImageHeight, _ destRect, _ RasterPaintSizeMode.Fit, _ RasterPaintAlignMode.Center, _ RasterPaintAlignMode.Center) Dim clipRect As LeadRect = 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 Then Dim xform As RasterRegionXForm = GetXForm(destRect) RasterImagePainter.FillRegion(image, 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 LeadRect = LeadRect.FromLTRB(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Bottom) destRect = RasterImage.CalculatePaintModeRectangle( _ image.ImageWidth, _ image.ImageHeight, _ destRect, _ RasterPaintSizeMode.Fit, _ RasterPaintAlignMode.Center, _ RasterPaintAlignMode.Center) Dim xform As RasterRegionXForm = GetXForm(destRect) Using g As Graphics = CreateGraphics() RasterImagePainter.FrameRegion(image, g, xform, frameIndex) End Using ' advance to next frame frameIndex = frameIndex + 1 If frameIndex > RasterImagePainter.MaxRegionFrameIndex Then frameIndex = 0 End If End Sub End Class Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class |
C# | Copy Code |
---|---|
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:\Users\Public\Documents\LEADTOOLS Images"; } |
If the region includes non-contiguous shapes, each shape is outlined. The outline, itself, is inside the region.
Before calling this method, create a Leadtools.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 RasterImage and GDI/GDI+.
For more information, refer to Creating a Region and Working with the Existing Region.
Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)