Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
AddGdiRegionToRegion Method
See Also  Example
Leadtools Namespace > RasterImage Class : AddGdiRegionToRegion Method



xform
RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates. If you specify null (Nothing in Visual Basic) in this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
region
The Windows region handle to add.
combineMode
The action to take regarding the existing image region, if one is defined.
Creates or updates the image region by adding the specified Windows region handle.

Syntax

Visual Basic (Declaration)  
Public Sub AddGdiRegionToRegion( _
   ByVal xform As RasterRegionXForm, _
   ByVal region As IntPtr, _
   ByVal combineMode As RasterRegionCombineMode _
) 
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim xform As RasterRegionXForm
Dim region As IntPtr
Dim combineMode As RasterRegionCombineMode
 
instance.AddGdiRegionToRegion(xform, region, combineMode)
C#  
public void AddGdiRegionToRegion( 
   RasterRegionXForm xform,
   IntPtr region,
   RasterRegionCombineMode combineMode
)
C++/CLI  
public:
void AddGdiRegionToRegion( 
   RasterRegionXForm^ xform,
   IntPtr region,
   RasterRegionCombineMode combineMode
) 

Parameters

xform
RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates. If you specify null (Nothing in Visual Basic) in this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
region
The Windows region handle to add.
combineMode
The action to take regarding the existing image region, if one is defined.

Example

Visual Basic Copy Code
Public Sub AddGdiRegionToRegionExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
   Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_AddGdiRegionToRegion.bmp"

   ' Load the image
   Dim image As RasterImage = codecs.Load(srcFileName)

   ' Create a GDI+ region
   Dim region As Region

   Dim path As GraphicsPath = New GraphicsPath()
   Try
      path.AddRectangle(New Rectangle(100, 100, 200, 200))
      path.AddEllipse(New Rectangle(150, 150, 200, 200))
      region = New Region(path)
   Finally
      CType(path, IDisposable).Dispose()
   End Try

   ' Get the Windows GDI handle for this region
   Dim hrgn As IntPtr

   Dim btmp As Bitmap = New Bitmap(1, 1)
   Try
      Dim g As Graphics = Graphics.FromImage(btmp)
      Try
         hrgn = region.GetHrgn(g)
      Finally
         CType(g, IDisposable).Dispose()
      End Try
   Finally
      CType(btmp, IDisposable).Dispose()
   End Try

   ' Add this region to the raster image
   image.AddGdiRegionToRegion(Nothing, hrgn, RasterRegionCombineMode.Set)

   region.ReleaseHrgn(hrgn)
   region.Dispose()

   ' Draw something on the image
   Dim command As InvertCommand = New InvertCommand()
   command.Run(image)

   ' Save the image
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24)

   image.Dispose()
   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
public void AddGdiRegionToRegionExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_AddGdiRegionToRegion.bmp"; 
 
   // Load the image 
   RasterImage image = codecs.Load(srcFileName); 
 
   // Create a GDI+ region 
   Region region; 
 
   using(GraphicsPath path = new GraphicsPath()) 
   { 
      path.AddRectangle(new Rectangle(100, 100, 200, 200)); 
      path.AddEllipse(new Rectangle(150, 150, 200, 200)); 
      region = new Region(path); 
   } 
 
   // Get the Windows GDI handle for this region 
   IntPtr hrgn; 
 
   using(Bitmap btmp = new Bitmap(1, 1)) 
   { 
      using(Graphics graphics = Graphics.FromImage(btmp)) 
         hrgn = region.GetHrgn(graphics); 
   } 
 
   // Add this region to the raster image 
   image.AddGdiRegionToRegion(null, hrgn, RasterRegionCombineMode.Set); 
 
   region.ReleaseHrgn(hrgn); 
   region.Dispose(); 
 
   // Draw something on the image 
   InvertCommand command = new InvertCommand(); 
   command.Run(image); 
 
   // Save the image 
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24); 
 
   image.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

To update an existing region, you specify how the new region is to be combined with the existing one using the combineMode parameter. For more information, refer to RasterRegionCombineMode.

For more information, refer to Creating a Region.

For more information, refer to Saving A Region.

For more information, refer to 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