LEADTOOLS (Leadtools assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
GetData Method
See Also 
Leadtools Namespace > RasterRegion Class : GetData Method



Returns an array of System.Byte that represents the information that describes this RasterRegion. Supported in Silverlight, Windows Phone 7

Syntax

Visual Basic (Declaration) 
Public Function GetData() As Byte()
Visual Basic (Usage)Copy Code
Dim instance As RasterRegion
Dim value() As Byte
 
value = instance.GetData()
C# 
public byte[] GetData()
C++/CLI 
public:
array<byte>^ GetData(); 

Return Value

An array of System.Byte that represents the information that describes this RasterRegion.

Example

This example will loads an image, adds a region to it, gets the RasterRegion object from the image and set it to disk. It will then re-load this data from disk and set it back to another image.

Visual BasicCopy Code
Public Sub RasterRegionDataExample()
      Dim codecs As New RasterCodecs()

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
      Dim destFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WithRegion1.bmp")
      Dim regionFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Region.bin")
      Dim destFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WithRegion2.bmp")

      Dim region As RasterRegion = Nothing

      ' Load the source image
      Using image As RasterImage = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
         ' Add an elliptical region to it
         image.AddEllipseToRegion(Nothing, 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
         Dim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow))
         cmd.Run(image)

         codecs.Save(image, destFileName1, RasterImageFormat.Bmp, 24)

         ' Get the region
         region = image.GetRegion(Nothing)
      End Using

      ' Save this region to disk
      Dim data() As Byte = 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 image As RasterImage = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
         ' Create a region from the data we saved on disk
         data = File.ReadAllBytes(regionFileName)
         region = New RasterRegion(data)
         ' Set this region into the image
         image.SetRegion(Nothing, region, RasterRegionCombineMode.Set)
         region.Dispose()

         ' Fill the image with a color and save it to disk to show the region
         Dim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow))
         cmd.Run(image)

         codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24)
      End Using

      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void RasterRegionDataExample()
   {
      RasterCodecs codecs = new RasterCodecs();

      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;

      // 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);
      }

      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
SilverlightVBCopy Code

Remarks

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

If this RasterRegion is empty, then this method will return an array of 0 items.

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only), Windows Phone 7

See Also