←Select platform

GetGdiRegionData Method

Summary
Gets the GDI data that describes the image region.
Syntax
C#
C++/CLI
Python
public static byte[] GetGdiRegionData( 
   RasterImage image, 
   RasterRegionXForm xform 
) 
public: 
static array<byte>^ GetGdiRegionData(  
   RasterImage^ image, 
   RasterRegionXForm^ xform 
)  
def GetGdiRegionData(self,image,xform): 

Parameters

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.

Return Value

An array of System.Byte that contains the information that describes the region in this Leadtools.RasterImage object.

Remarks

Used with AddGdiDataToRegion to load or save an image region.

The data returned by this method is the equivalent of the data returned using the Windows GetRegionData API.

To get the region data as GDI+ System.Drawing.Drawing2D.RegionData object, use GetGdiPlusRegionData and AddGdiPlusDataToRegion.

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+.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
 
public void GdiRegionDataExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_GdiRegionDataOriginal.bmp"); 
   string regionFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_GdiRegionData.bin"); 
   string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_GdiRegionDataLoaded.bmp"); 
 
   RegionDataBefore(codecs, srcFileName, destFileName1, regionFileName); 
   RegionDataAfter(codecs, srcFileName, destFileName2, regionFileName); 
 
   codecs.Dispose(); 
} 
 
private void RegionDataBefore(RasterCodecs codecs, string imageFileName, string destFileName, string regionFileName) 
{ 
   // Load the image 
   using (RasterImage image = codecs.Load(imageFileName)) 
   { 
      // 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); 
 
      // Draw something on the image 
      InvertCommand command = new InvertCommand(); 
      command.Run(image); 
 
      // Save the region and the image 
      codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24); 
 
      byte[] data = RasterRegionConverter.GetGdiRegionData(image, null); 
      using (FileStream fs = File.Create(regionFileName)) 
      { 
         fs.Write(data, 0, data.Length); 
      } 
   } 
} 
 
private void RegionDataAfter(RasterCodecs codecs, string imageFileName, string destFileName, string regionFileName) 
{ 
   // Load the image 
   using (RasterImage image = codecs.Load(imageFileName)) 
   { 
      // Load the region from the file and apply it to the image 
      byte[] data; 
 
      using (FileStream fs = File.OpenRead(regionFileName)) 
      { 
         data = new byte[fs.Length]; 
         fs.Read(data, 0, data.Length); 
      } 
 
      RasterRegionConverter.AddGdiDataToRegion(image, null, data, 0, RasterRegionCombineMode.Set); 
 
      // Draw something on the image 
      InvertCommand command = new InvertCommand(); 
      command.Run(image); 
 
      // Save the image 
      codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools.Drawing Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.