public static RasterRegion ConvertFromRegion(Region region)
region
The source GDI+ region. This parameter cannot be null (Nothing in VB).
The LEADTOOLS Leadtools.RasterRegion object this method creates. You must dispose this object after using it.
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 GDI HRGN and System.Drawing (GDI+) System.Drawing.Region object.
For more information refer to RasterImage and GDI/GDI+.
using Leadtools;using Leadtools.Codecs;using Leadtools.Drawing;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;public void RasterRegionConverterExample(){// Load an imagestring 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 GDI+, create an elliptical regionRegion gdipRegion;using (GraphicsPath path = new GraphicsPath()){path.AddEllipse(100, 200, 400, 300);gdipRegion = new Region(path);}// Create a RasterRegion from this regionusing (RasterRegion region = RasterRegionConverter.ConvertFromRegion(gdipRegion)){// Add this region to the imageimage.SetRegion(null, region, RasterRegionCombineMode.Set);}gdipRegion.Dispose();// Fill the image with a colorFillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red));cmd.Run(image);// Save itcodecs.Save(image, dstFileName1, RasterImageFormat.Jpeg, 24);// Now get the GDI+ region from the imageusing (RasterRegion region = image.GetRegion(null)){// Convert it to GDI+gdipRegion = RasterRegionConverter.ConvertToRegion(region, null);}// Move the region 100 pixels to the right and bottomgdipRegion.Translate(100, 100);// Re-set it into the image, fill again and save// Create a RasterRegion from this regionusing (RasterRegion region = RasterRegionConverter.ConvertFromRegion(gdipRegion)){// Add this region to the imageimage.SetRegion(null, region, RasterRegionCombineMode.Set);}gdipRegion.Dispose();// Fill the image with a colorcmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));cmd.Run(image);// Save itcodecs.Save(image, dstFileName2, RasterImageFormat.Jpeg, 24);image.Dispose();codecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";}