←Select platform

ConvertFromGeometry Method

Summary
Converts a WPF System.Windows.Media.Geometry object to a LEADTOOLS Leadtools.RasterRegion.
Syntax
C#
C++/CLI
public static RasterRegion ConvertFromGeometry( 
   Geometry geometry 
) 
public: 
static RasterRegion^ ConvertFromGeometry(  
   Geometry^ geometry 
)  

Parameters

geometry
The WPF source geometry. This parameter cannot be null (Nothing in VB).

Return Value

The LEADTOOLS Leadtools.RasterRegion object this method creates. You must dispose this object after using it.

Remarks

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.

Example
C#
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:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.