←Select platform

SetData Method

Summary
Overrides the data of this RasterRegion from an array of Byte.
Syntax
C#
C++/CLI
Java
Python
public void SetData( 
   byte[] data 
) 
public void setData(byte[] data) 
public: 
void SetData(  
   array<byte>^ data 
)  
def SetData(self,data): 

Parameters

data
An array of Byte that represents the information that describes a RasterRegion.

Remarks

You can use the GetData and SetData methods to save and load the content of a region to disk or memory.

If  data is an array of 0 items or is null, then this method will make the RasterRegion object empty. This is the equivalent of calling MakeEmpty.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
 
 
public void RasterRegionDataExample() 
{ 
 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WithRegion1.bmp"); 
   string regionFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Region.bin"); 
   string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WithRegion2.bmp"); 
 
   RasterRegion region = null; 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      // Load the source image 
      using (RasterImage image = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
      { 
         // Add an elliptical region to it 
         image.AddEllipseToRegion(null, new LeadRect(0, 0, image.ImageWidth, image.ImageHeight), RasterRegionCombineMode.Set); 
 
         // Fill the image with a color and save it to disk to show the region 
         FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow)); 
         cmd.Run(image); 
 
         codecs.Save(image, destFileName1, RasterImageFormat.Bmp, 24); 
 
         // Get the region 
         region = image.GetRegion(null); 
      } 
 
      // Save this region to disk 
      byte[] data = region.GetData(); 
      File.WriteAllBytes(regionFileName, data); 
 
      // Dispose the region 
      region.Dispose(); 
 
      // Now, reload the image and region from disk, set the region into the image directly 
      // from the data we save, re-fill and save again 
      using (RasterImage image = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
      { 
         // Create a region from the data we saved on disk 
         data = File.ReadAllBytes(regionFileName); 
         using (region = new RasterRegion(data)) 
         { 
            // Set this region into the image 
            image.SetRegion(null, region, RasterRegionCombineMode.Set); 
         } 
 
         // Fill the image with a color and save it to disk to show the region 
         FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow)); 
         cmd.Run(image); 
 
         codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools Assembly

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