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



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

Syntax

Visual Basic (Declaration)  
Public Sub AddGdiPlusDataToRegion( _
   ByVal xform As RasterRegionXForm, _
   ByVal data As RegionData, _
   ByVal combineMode As RasterRegionCombineMode _
) 
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim xform As RasterRegionXForm
Dim data As RegionData
Dim combineMode As RasterRegionCombineMode
 
instance.AddGdiPlusDataToRegion(xform, data, combineMode)
C#  
public void AddGdiPlusDataToRegion( 
   RasterRegionXForm xform,
   RegionData data,
   RasterRegionCombineMode combineMode
)
C++/CLI  
public:
void AddGdiPlusDataToRegion( 
   RasterRegionXForm^ xform,
   RegionData data,
   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) for this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
data
A RegionData object that defines the region to add.
combineMode
The action to take regarding the existing image region, if one is defined.

Example

This example will use AddGdiPlusDataToRegion and GetGdiPlusRegionData to add an elliptical region to a RasterImage, gets the region as a GDI+ RegionData object then re-sets it in another image.

Visual Basic Copy Code
Private Sub TestGdiPlusRegionData()
   RasterCodecs.Startup()
   Dim codecs As New RasterCodecs()
   Dim rgnData As RegionData = Nothing

   ' Load the image and add a region to it
   Dim inFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Image1.cmp"
   Dim outFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Image1_GdiPlusRegion.cmp"

   Using image As RasterImage = codecs.Load(inFileName)
      ' Add an elliptical region to the image
      image.AddEllipseToRegion(Nothing, New Rectangle(0, 0, image.ImageWidth, image.ImageHeight), RasterRegionCombineMode.Set)

      ' Get a GDI+ RegionData object from the image region
      rgnData = image.GetGdiPlusRegionData(Nothing)
   End Using

   ' Now re-load the image
   Using image As RasterImage = codecs.Load(inFileName)
      ' Create a GDI+ region object from the RegionData we saved
      Using rgn As New Region(rgnData)
         ' Add it to the image
         image.AddGdiPlusRegionToRegion(Nothing, rgn, RasterRegionCombineMode.Set)
      End Using

      ' Invert the region area
      Dim cmd As New InvertCommand()
      cmd.Run(image)

      ' Save this image back to disk
      codecs.Save(image, outFileName, RasterImageFormat.Cmp, 24)
   End Using

   ' Clean up
   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
private void TestGdiPlusRegionData() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   RegionData rgnData = null; 
 
   // Load the image and add a region to it 
   string inFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Image1.cmp"; 
   string outFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Image1_GdiPlusRegion.cmp"; 
 
   using(RasterImage image = codecs.Load(inFileName)) 
   { 
      // Add an elliptical region to the image 
      image.AddEllipseToRegion(null, new Rectangle(0, 0, image.ImageWidth, image.ImageHeight), RasterRegionCombineMode.Set); 
 
      // Get a GDI+ RegionData object from the image region 
      rgnData = image.GetGdiPlusRegionData(null); 
   } 
 
   // Now re-load the image 
   using(RasterImage image = codecs.Load(inFileName)) 
   { 
      // Create a GDI+ region object from the RegionData we saved 
      using(Region rgn = new Region(rgnData)) 
      { 
         // Add it to the image 
         image.AddGdiPlusRegionToRegion(null, rgn, RasterRegionCombineMode.Set); 
      } 
 
      // Invert the region area 
      InvertCommand cmd = new InvertCommand(); 
      cmd.Run(image); 
 
      // Save this image back to disk 
      codecs.Save(image, outFileName, RasterImageFormat.Cmp, 24); 
   } 
 
   // Clean up 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

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

This method can be used to copy the region data from one RasterImage to another, using the GetGdiPlusRegionData method.

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