AddGeometryToRegion Method
Summary
Creates or updates a LEADTOOLS image region by adding the specified WPF geometry.
Syntax
Parameters
geometry
The WPF geometry to add.
combineMode
The action to take regarding the existing image region, if one is defined.
Example
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.Windows.Media;
public void AddGeometryToRegionExample()
{
// Load an image
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string dstFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_AddGeometryToRegion.jpg");
RasterCodecs codecs = new RasterCodecs();
RasterImage image = codecs.Load(srcFileName);
// We will add an ellipse region to the image
// Using WPF, create an elliptical geometry
// Create the ellipse geometry to add to the Path
EllipseGeometry ellipseGeometry = new EllipseGeometry();
ellipseGeometry.Center = new Point(250, 250);
ellipseGeometry.RadiusX = 200;
ellipseGeometry.RadiusY = 150;
Geometry geometry = ellipseGeometry;
// Add this geometry to the image
RasterRegionConverter.AddGeometryToRegion(image, null, geometry, RasterRegionCombineMode.Set);
// Fill the image with a color
FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red));
cmd.Run(image);
// Save it
codecs.Save(image, dstFileName, RasterImageFormat.Jpeg, 24);
image.Dispose();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.Windows.Media
Public Sub AddGeometryToRegionExample()
' Load an image
Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
Dim dstFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_AddGeometryToRegion.jpg")
Dim codecs As New RasterCodecs()
Dim image As RasterImage = codecs.Load(srcFileName)
' We will add an ellipse region to the image
' Using WPF, create an elliptical geometry
' Create the ellipse geometry to add to the Path
Dim ellipseGeometry As New EllipseGeometry()
ellipseGeometry.Center = New Point(250, 250)
ellipseGeometry.RadiusX = 200
ellipseGeometry.RadiusY = 150
Dim geometry As Geometry = ellipseGeometry
' Add this geometry to the image
RasterRegionConverter.AddGeometryToRegion(image, Nothing, geometry, RasterRegionCombineMode.Set)
' Fill the image with a color
Dim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red))
cmd.Run(image)
' Save it
codecs.Save(image, dstFileName, RasterImageFormat.Jpeg, 24)
image.Dispose()
codecs.Dispose()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class