Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
AddDataToRegion Method
See Also  Example
Leadtools Namespace > RasterImage Class : AddDataToRegion Method



xform
RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates. If you specify null (Nothing in Visual Basic) in this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
data
Array of bytes that describe the region data.
dataOffset
Zero-based index into data.
combineMode
The action to take regarding the existing image region, if one is defined.
Creates or updates the image region using the specified region data.

Syntax

Visual Basic (Declaration)  
Public Sub AddDataToRegion( _
   ByVal xform As RasterRegionXForm, _
   ByVal data() As Byte, _
   ByVal dataOffset As Integer, _
   ByVal combineMode As RasterRegionCombineMode _
) 
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim xform As RasterRegionXForm
Dim data() As Byte
Dim dataOffset As Integer
Dim combineMode As RasterRegionCombineMode
 
instance.AddDataToRegion(xform, data, dataOffset, combineMode)
C#  
public void AddDataToRegion( 
   RasterRegionXForm xform,
   byte[] data,
   int dataOffset,
   RasterRegionCombineMode combineMode
)
C++/CLI  
public:
void AddDataToRegion( 
   RasterRegionXForm^ xform,
   array<byte>^ data,
   int dataOffset,
   RasterRegionCombineMode combineMode
) 

Parameters

xform
RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates. If you specify null (Nothing in Visual Basic) in this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
data
Array of bytes that describe the region data.
dataOffset
Zero-based index into data.
combineMode
The action to take regarding the existing image region, if one is defined.

Example

Refer to AddDataToRegion.

This example will show how to use GetRegionData and AddDataToRegion to save/load an image region

Visual Basic Copy Code
Public Sub RegionDataExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
   Dim destFileName1 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RegionDataOriginal.bmp"
   Dim regionFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RegionData.bin"
   Dim destFileName2 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RegionDataLoaded.bmp"

   RegionDataBefore(codecs, srcFileName, destFileName1, regionFileName)
   RegionDataAfter(codecs, srcFileName, destFileName2, regionFileName)

   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub

Private Sub RegionDataBefore(ByVal codecs As RasterCodecs, ByVal imageFileName As String, ByVal destFileName As String, ByVal regionFileName As String)
   ' Load the image
   Dim image As RasterImage = codecs.Load(imageFileName)

   ' Add a polygon region to the image
   Dim x1 As Integer = image.ImageWidth \ 4
   Dim y1 As Integer = image.ImageHeight \ 4
   Dim x2 As Integer = image.ImageWidth \ 3
   Dim y2 As Integer = image.ImageHeight \ 3

   Dim pts As Point() = {New Point(x1, y1), New Point(x2, y1), New Point(x1, y2), New Point(x2, y2)}

   image.AddPolygonToRegion(Nothing, pts, FillMode.Winding, RasterRegionCombineMode.Set)

   ' Draw something on the image
   Dim command As InvertCommand = New InvertCommand()
   command.Run(image)

   ' Save the region and the image
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24)

   Dim data As Byte() = image.GetRegionData(Nothing)
   Dim fs As FileStream = File.Create(regionFileName)
   Try
      fs.Write(data, 0, data.Length)
   Finally
      CType(fs, IDisposable).Dispose()
   End Try

   image.Dispose()
End Sub

Private Sub RegionDataAfter(ByVal codecs As RasterCodecs, ByVal imageFileName As String, ByVal destFileName As String, ByVal regionFileName As String)
   ' Load the image
   Dim image As RasterImage = codecs.Load(imageFileName)

   ' Load the region from the file and apply it to the image
   Dim data As Byte()

   Dim fs As FileStream = File.OpenRead(regionFileName)
   Try
      data = New Byte(Convert.ToByte(fs.Length - 1)) {}
      fs.Read(data, 0, data.Length)
   Finally
      CType(fs, IDisposable).Dispose()
   End Try

   image.AddDataToRegion(Nothing, data, 0, RasterRegionCombineMode.Set)

   ' Draw something on the image
   Dim command As InvertCommand = New InvertCommand()
   command.Run(image)

   ' Save the image
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24)

   image.Dispose()
End Sub
C# Copy Code
public void RegionDataExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName1 = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RegionDataOriginal.bmp"; 
   string regionFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RegionData.bin"; 
   string destFileName2 = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RegionDataLoaded.bmp"; 
 
   RegionDataBefore(codecs, srcFileName, destFileName1, regionFileName); 
   RegionDataAfter(codecs, srcFileName, destFileName2, regionFileName); 
 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 

 
void RegionDataBefore(RasterCodecs codecs, string imageFileName, string destFileName, string regionFileName) 

   // Load the image 
   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; 
 
   Point[] pts = 
   { 
      new Point(x1, y1), 
      new Point(x2, y1), 
      new Point(x1, y2), 
      new Point(x2, y2) 
   }; 
 
   image.AddPolygonToRegion(null, pts, FillMode.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 = image.GetRegionData(null); 
   using(FileStream fs = File.Create(regionFileName)) 
      fs.Write(data, 0, data.Length); 
 
   image.Dispose(); 

 
void RegionDataAfter(RasterCodecs codecs, string imageFileName, string destFileName, string regionFileName) 

   // Load the image 
   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); 
   } 
 
   image.AddDataToRegion(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); 
 
   image.Dispose(); 
}

Remarks

To update an existing region, specify how the new region is to be combined with the existing one using the combineMode parameter. For more information, refer to RasterRegionCombineMode.

This method can only be used to copy the region data from one RasterImage to another, using the GetRegionData method.

For more information, refer to Creating a Region.

For more information, refer to Saving A Region.

For more information, refer to Working with the Existing Region.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also