public byte[] GetData() Public Function GetData() As Byte() public byte[] getData() public:array<byte>^ GetData();
An array of Byte that represents the information that describes this RasterRegion.
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.
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.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using LeadtoolsExamples.Common;public void RasterRegionDataExample(){string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");string destFileName1 = Path.Combine(ImagesPath.Path, "Image1_WithRegion1.bmp");string regionFileName = Path.Combine(ImagesPath.Path, "Image1_Region.bin");string destFileName2 = Path.Combine(ImagesPath.Path, "Image1_WithRegion2.bmp");RasterRegion region = null;using (RasterCodecs codecs = new RasterCodecs()){// Load the source imageusing (RasterImage image = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)){// Add an elliptical region to itimage.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 regionFillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));cmd.Run(image);codecs.Save(image, destFileName1, RasterImageFormat.Bmp, 24);// Get the regionregion = image.GetRegion(null);}// Save this region to diskbyte[] data = region.GetData();File.WriteAllBytes(regionFileName, data);// Dispose the regionregion.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 againusing (RasterImage image = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)){// Create a region from the data we saved on diskdata = File.ReadAllBytes(regionFileName);using (region = new RasterRegion(data)){// Set this region into the imageimage.SetRegion(null, region, RasterRegionCombineMode.Set);}// Fill the image with a color and save it to disk to show the regionFillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));cmd.Run(image);codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24);}}}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingPublic 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 imageUsing image As RasterImage = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)' Add an elliptical region to itimage.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 regionDim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow))cmd.Run(image)codecs.Save(image, destFileName1, RasterImageFormat.Bmp, 24)' Get the regionregion = image.GetRegion(Nothing)End Using' Save this region to diskDim data() As Byte = region.GetData()File.WriteAllBytes(regionFileName, data)' Dispose the regionregion.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 againUsing image As RasterImage = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)' Create a region from the data we saved on diskdata = File.ReadAllBytes(regionFileName)region = New RasterRegion(data)' Set this region into the imageimage.SetRegion(Nothing, region, RasterRegionCombineMode.Set)region.Dispose()' Fill the image with a color and save it to disk to show the regionDim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow))cmd.Run(image)codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24)End Usingcodecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
