public static RegionData GetGdiPlusRegionData(
RasterImage image,
RasterRegionXForm xform
)
image
The source image.
xform
Leadtools.RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates. If you specify null (Nothing in VB) for this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
A System.Drawing.Drawing2D.RegionData object that contains the information that describes the region in this Leadtools.RasterImage object.
Used with AddGdiPlusDataToRegion to load or save an image region.
The data returned by this method is the equivalent of the data returned using the GDI+ System.Drawing.Region.GetRegionData method.
To get the region data as Windows API HRGN data, use GetGdiRegionData and AddGdiDataToRegion.
To get the region data as platform independent byte array, use RasterRegion.GetData and RasterRegion.SetData.
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 GdiPlusRegionDataExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_GdiPlusData.bmp");
RegionData gdipRegionData = null;
// Load the source image
using (RasterImage image = codecs.Load(srcFileName))
{
// Add a polygon region to it
// Add a polygon region to the image
int x1 = image.ImageWidth / 4;
int y1 = image.ImageHeight / 4;
int x2 = image.ImageWidth / 3;
int y2 = image.ImageHeight / 3;
LeadPoint[] pts =
{
new LeadPoint(x1, y1),
new LeadPoint(x2, y1),
new LeadPoint(x1, y2),
new LeadPoint(x2, y2)
};
image.AddPolygonToRegion(null, pts, LeadFillMode.Winding, RasterRegionCombineMode.Set);
// Save the region as a GDI+ RegionData object
gdipRegionData = RasterRegionConverter.GetGdiPlusRegionData(image, null);
}
// Re-load the source image
using (RasterImage image = codecs.Load(srcFileName))
{
// Add the GDI+ region data we saved to it
RasterRegionConverter.AddGdiPlusDataToRegion(image, null, gdipRegionData, RasterRegionCombineMode.Set);
// Fill this region with Yellow
FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));
cmd.Run(image);
// Save this image
codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24);
}
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}