Creates a GDI+ region that is a snapshot of this
RasterImage region.
Syntax
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 Basic |
Copy 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"
Dim image As RasterImage = codecs.Load(srcFileName)
Dim rc As Rectangle = New Rectangle(image.Width \ 3, image.Height \ 3, image.Width \ 3, image.Height \ 3) image.AddEllipseToRegion(Nothing, rc, RasterRegionCombineMode.Set)
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
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
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