Converts between a LEADTOOLS Leadtools.RasterRegion and Windows Presentation Foundation (WPF) System.Windows.Media.Geometry objects.
public static class RasterRegionConverter
Public MustInherit NotInheritable Class RasterRegionConverter
public ref class RasterRegionConverter abstract sealed
This class lets you easily convert between a LEADTOOLS Leadtools.RasterRegion object and a WPF System.Windows.Media.Geometry object.
The LEADTOOLS Leadtools.RasterRegion class provides a platform independent representation of an area of interest in a Leadtools.RasterImage that can be used in any platform supported by LEADTOOLS such as GDI, GDI+, and WPF. Use this class To convert a LEADTOOLS Leadtools.RasterRegion object to/from a WPF System.Windows.Media.Geometry object.
For more information refer to RasterImage and WPF.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.Windows.Media;
public void RasterRegionConverterExample()
{
// Load an image
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string dstFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Ellipse.jpg");
string dstFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_EllipseTranslated.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;
// Create a RasterRegion from this region
using (RasterRegion region = RasterRegionConverter.ConvertFromGeometry(geometry))
{
// Add this region to the image
image.SetRegion(null, region, RasterRegionCombineMode.Set);
}
// Fill the image with a color
FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red));
cmd.Run(image);
// Save it
codecs.Save(image, dstFileName1, RasterImageFormat.Jpeg, 24);
// Now get the WPF geometry from the image
using (RasterRegion region = image.GetRegion(null))
{
geometry = RasterRegionConverter.ConvertToGeometry(region, null);
}
// Move the geometry 100 pixels to the right and bottom
geometry.Transform = new TranslateTransform(100, 100);
// Re-set it into the image, fill again and save
// Create a RasterRegion from this region
using (RasterRegion region = RasterRegionConverter.ConvertFromGeometry(geometry))
{
// Add this region to the image
image.SetRegion(null, region, RasterRegionCombineMode.Set);
}
// Fill the image with a color
cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));
cmd.Run(image);
// Save it
codecs.Save(image, dstFileName2, 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 RasterRegionConverterExample()
' Load an image
Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
Dim dstFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Ellipse.jpg")
Dim dstFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_EllipseTranslated.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
' Create a RasterRegion from this region
Using region As RasterRegion = RasterRegionConverter.ConvertFromGeometry(geometry)
' Add this region to the image
image.SetRegion(Nothing, region, RasterRegionCombineMode.Set)
End Using
' Fill the image with a color
Dim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red))
cmd.Run(image)
' Save it
codecs.Save(image, dstFileName1, RasterImageFormat.Jpeg, 24)
' Now get the WPF geometry from the image
Using region As RasterRegion = image.GetRegion(Nothing)
geometry = RasterRegionConverter.ConvertToGeometry(region, Nothing)
End Using
' Move the geometry 100 pixels to the right and bottom
geometry.Transform = New TranslateTransform(100, 100)
' Re-set it into the image, fill again and save
' Create a RasterRegion from this region
Using region As RasterRegion = RasterRegionConverter.ConvertFromGeometry(geometry)
' Add this region to the image
image.SetRegion(Nothing, region, RasterRegionCombineMode.Set)
End Using
' Fill the image with a color
cmd = New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow))
cmd.Run(image)
' Save it
codecs.Save(image, dstFileName2, 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
c#[Silverlight C# Example]
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.Windows.Media;
public void RasterRegionConverterExample()
{
// Load an image
string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp";
RasterCodecs codecs = new RasterCodecs();
RasterImage image = codecs.Load(srcFileName);
// We will add a region to the image
RasterRegion region = new RasterRegion(new LeadRect(250, 250, 200, 150));
image.SetRegion(null, region, RasterRegionCombineMode.Set);
// Now get the WPF geometry from the image
Geometry geometry;
using (RasterRegion rgn = image.GetRegion(null))
{
geometry = RasterRegionConverter.ConvertToGeometry(region, null);
// Create a Path to be drawn to the screen.
System.Windows.Shapes.Path myPath = new System.Windows.Shapes.Path();
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255);
myPath.Fill = mySolidColorBrush;
myPath.Data = geometry;
// Add path shape to the UI.
StackPanel mainPanel = new StackPanel();
mainPanel.Children.Add(myPath);
}
image.Dispose();
}
vb[Silverlight VB Example]
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.Windows.Media
Public Sub RasterRegionConverterExample()
' Load an image
Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path & "Image1.cmp"
Dim codecs As RasterCodecs = New RasterCodecs()
Dim image As RasterImage = codecs.Load(srcFileName)
' We will add a region to the image
Dim region As RasterRegion = New RasterRegion(New LeadRect(250, 250, 200, 150))
image.SetRegion(Nothing, region, RasterRegionCombineMode.Set)
' Now get the WPF geometry from the image
Dim geometry As Geometry
Using rgn As RasterRegion = image.GetRegion(Nothing)
geometry = RasterRegionConverter.ConvertToGeometry(region, Nothing)
' Create a Path to be drawn to the screen.
Dim myPath As System.Windows.Shapes.Path = New System.Windows.Shapes.Path()
Dim mySolidColorBrush As SolidColorBrush = New SolidColorBrush()
mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255)
myPath.Fill = mySolidColorBrush
myPath.Data = geometry
' Add path shape to the UI.
Dim mainPanel As StackPanel = New StackPanel()
mainPanel.Children.Add(myPath)
End Using
image.Dispose()
End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.