Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
RegionToGdiPlusRegion Method
See Also  Example
Leadtools Namespace > RasterImage Class : RegionToGdiPlusRegion 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.
Creates a GDI+ region that is a snapshot of this RasterImage region.

Syntax

Visual Basic (Declaration) 
Public Function RegionToGdiPlusRegion( _
   ByVal xform As RasterRegionXForm _
) As Region
Visual Basic (Usage)Copy Code
Dim instance As RasterImage
Dim xform As RasterRegionXForm
Dim value As Region
 
value = instance.RegionToGdiPlusRegion(xform)
C# 
public Region RegionToGdiPlusRegion( 
   RasterRegionXForm xform
)
C++/CLI 
public:
Region RegionToGdiPlusRegion( 
   RasterRegionXForm^ xform
) 

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.

Return Value

The GDI+ region this method creates.

Example

Visual BasicCopy Code
Public Sub RegionToGdiPlusRegionExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
   Dim destFileName1 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RegionToGdiPlusRegion.bmp"
   Dim destFileName2 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_AddGdiPlusRegionToRegion.bmp"

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

   ' Add an ellipse inside a rectangle region to the image

   Dim rc As Rectangle = New Rectangle(image.Width \ 3, image.Height \ 3, image.Width \ 3, image.Height \ 3)
   image.AddEllipseToRegion(Nothing, rc, RasterRegionCombineMode.Set)

   ' Create a GDI+ image from this raster image, then obtain a Graphics
   ' object to the GDI+ image, apply the region to it then fill it with red color
   Dim region As Region

   Dim gdiPlusImage As Image = image.ConvertToGdiPlusImage()
   Try
      Dim g As Graphics = Graphics.FromImage(gdiPlusImage)
      Try
         region = image.RegionToGdiPlusRegion(Nothing)
         g.Clip = region

         ' This call should only fill the ellipse
         g.FillRectangle(Brushes.Red, 0, 0, image.Width, image.Height)
      Finally
         CType(g, IDisposable).Dispose()
      End Try

      gdiPlusImage.Save(destFileName1, ImageFormat.Bmp)
   Finally
      CType(gdiPlusImage, IDisposable).Dispose()
   End Try

   ' Empty the region in the raster image and re-add it through the
   ' region object we got with RegionToGdiPlusRegion
   image.MakeRegionEmpty()
   image.AddGdiPlusRegionToRegion(Nothing, region, RasterRegionCombineMode.Set)
   Dim command As FillCommand = New FillCommand()
   command.Color = RasterColor.FromGdiPlusColor(Color.Red)
   command.Run(image)
   codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24)

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

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName1 = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RegionToGdiPlusRegion.bmp"; 
   string destFileName2 = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_AddGdiPlusRegionToRegion.bmp"; 
 
   // Load the image 
   RasterImage image = codecs.Load(srcFileName); 
 
   // Add an ellipse inside a rectangle region to the image 
 
   Rectangle rc = new Rectangle(image.Width / 3, image.Height / 3, image.Width / 3, image.Height / 3); 
   image.AddEllipseToRegion(null, rc, RasterRegionCombineMode.Set); 
 
   // Create a GDI+ image from this raster image, then obtain a Graphics 
   // object to the GDI+ image, apply the region to it then fill it with red color 
   Region region; 
 
   using(Image gdiPlusImage = image.ConvertToGdiPlusImage()) 
   { 
      using(Graphics graphics = Graphics.FromImage(gdiPlusImage)) 
      { 
         region = image.RegionToGdiPlusRegion(null); 
         graphics.Clip = region; 
 
         // This call should only fill the ellipse 
         graphics.FillRectangle(Brushes.Red, 0, 0, image.Width, image.Height); 
      } 
 
      gdiPlusImage.Save(destFileName1, ImageFormat.Bmp); 
   } 
 
   // Empty the region in the raster image and re-add it through the  
   // region object we got with RegionToGdiPlusRegion 
   image.MakeRegionEmpty(); 
   image.AddGdiPlusRegionToRegion(null, region, RasterRegionCombineMode.Set); 
   FillCommand command = new FillCommand(); 
   command.Color = RasterColor.FromGdiPlusColor(Color.Red); 
   command.Run(image); 
   codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24); 
 
   region.Dispose(); 
   image.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Requirements

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

See Also