LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

AddBorderToRegion Method

Example 





X coordinate of a point. The color of the specified point will be used to set the region.
Y coordinate of a point. The color of the specified point will be used to set the region.
Border color.
Lower tolerance values that set the lower stopping point for the region.
Upper tolerance values that set the lower stopping point for the region.
The action to take regarding the existing image region, if one is defined.
Creates a region of pixels with values that fall within a range defined by the value of a specific pixel and a lower and upper tolerance value but are not equal to the borderColor. .NET support WinRT support
Syntax
public void AddBorderToRegion( 
   int left,
   int top,
   RasterColor borderColor,
   RasterColor lowerToleranceColor,
   RasterColor upperToleranceColor,
   RasterRegionCombineMode combineMode
)
'Declaration
 
Public Sub AddBorderToRegion( _
   ByVal left As Integer, _
   ByVal top As Integer, _
   ByVal borderColor As RasterColor, _
   ByVal lowerToleranceColor As RasterColor, _
   ByVal upperToleranceColor As RasterColor, _
   ByVal combineMode As RasterRegionCombineMode _
) 
'Usage
 
Dim instance As RasterImage
Dim left As Integer
Dim top As Integer
Dim borderColor As RasterColor
Dim lowerToleranceColor As RasterColor
Dim upperToleranceColor As RasterColor
Dim combineMode As RasterRegionCombineMode
 
instance.AddBorderToRegion(left, top, borderColor, lowerToleranceColor, upperToleranceColor, combineMode)
public void AddBorderToRegion( 
   int left,
   int top,
   RasterColor borderColor,
   RasterColor lowerToleranceColor,
   RasterColor upperToleranceColor,
   RasterRegionCombineMode combineMode
)
 function Leadtools.RasterImage.AddBorderToRegion( 
   left ,
   top ,
   borderColor ,
   lowerToleranceColor ,
   upperToleranceColor ,
   combineMode 
)
public:
void AddBorderToRegion( 
   int left,
   int top,
   RasterColor borderColor,
   RasterColor lowerToleranceColor,
   RasterColor upperToleranceColor,
   RasterRegionCombineMode combineMode
) 

Parameters

left
X coordinate of a point. The color of the specified point will be used to set the region.
top
Y coordinate of a point. The color of the specified point will be used to set the region.
borderColor
Border color.
lowerToleranceColor
Lower tolerance values that set the lower stopping point for the region.
upperToleranceColor
Upper tolerance values that set the lower stopping point for the region.
combineMode
The action to take regarding the existing image region, if one is defined.
Remarks

For color bitmaps:

If the value of the pixel at (x, y) is (125, 125, 125) and lowerToleranceColor is (20,30,15), then the lower stopping point is (105, 95, 110). If upperToleranceColor is (20,30,15), then the upper stopping point is (145,155,140). In this case, the pixels with values between (105,95,110) and (145,155,140) are non-border pixels and will be included in the region. Any pixel with a value outside this range or equal to borderColor is considered a border pixel.

For gray scale bitmaps:

The minimum channel tolerance value of lowerToleranceColor will be used to set the lower stopping point, and the minimum channel tolerance value of upperToleranceColor will be used to set the upper stopping point. For example, if the value of the pixel at (x, y) is (125, 125, 125) and lowerToleranceColor is (20,30,15), the smallest value of the triplet (15) will be used to create the lower stopping point of (110,110,110). If upperToleranceColor is (10,25,20), the smallest value of that triplet (10) will be used to create the upper stopping point of (135,135,135). In this case, the pixels with values between (110, 110, 110) and (135,135,135) are non-border pixels and will be included in the region. Any pixel with a value outside this range or equal to borderColor is considered a border pixel.

This method does not support signed data images.

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

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.

Example
 
Public Sub AddBorderToRegionExample()
      Dim codecs As RasterCodecs = New RasterCodecs()

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
      Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_AddBorderToRegion.bmp")

      ' Load the image
      Dim image As RasterImage = codecs.Load(srcFileName)

      ' Posterize the image to decrease the number of colors
      Dim posterize As PosterizeCommand = New PosterizeCommand(16)
      posterize.Run(image)

      ' Specify a pixel in the upper left of the displayed image
      Dim pt As LeadPoint = New LeadPoint(image.ImageWidth \ 8, image.ImageHeight \ 8)

      ' Adjust the point in case the view perspective is not TopLeft
      pt = image.PointToImage(RasterViewPerspective.TopLeft, pt)

      ' Create a border region at this point
      Dim borderColor As RasterColor = image.GetPixelColor(pt.Y, pt.X)
      Dim lowerColor As RasterColor = New RasterColor(20, 30, 150)
      Dim upperColor As RasterColor = New RasterColor(15, 30, 10)
      image.AddBorderToRegion(pt.X, pt.Y, borderColor, lowerColor, upperColor, RasterRegionCombineMode.Set)

      ' Fill the region with blue
      Dim fill As FillCommand = New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Blue))
      fill.Run(image)

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

      image.Dispose()
      codecs.Dispose()
   End Sub

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

      string srcFileName = Path.Combine(LEAD_VARS.ImagesDir,"Image1.cmp");
      string destFileName = Path.Combine(LEAD_VARS.ImagesDir,"Image1_AddBorderToRegion.bmp");

      // Load the image
      RasterImage image = codecs.Load(srcFileName);

      // Posterize the image to decrease the number of colors
      PosterizeCommand posterize = new PosterizeCommand(16);
      posterize.Run(image);

      // Specify a pixel in the upper left of the displayed image
      LeadPoint pt = new LeadPoint(image.ImageWidth / 8, image.ImageHeight / 8);

      // Adjust the point in case the view perspective is not TopLeft
      pt = image.PointToImage(RasterViewPerspective.TopLeft, pt);

      // Create a border region at this point
      RasterColor borderColor = image.GetPixelColor(pt.Y, pt.X);
      RasterColor lowerColor = new RasterColor(20, 30, 150);
      RasterColor upperColor = new RasterColor(15, 30, 10);
      image.AddBorderToRegion(pt.X, pt.Y, borderColor, lowerColor, upperColor, RasterRegionCombineMode.Set);

      // Fill the region with blue
      FillCommand fill = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Blue));
      fill.Run(image);

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

      image.Dispose();
      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
RasterImageExamples.prototype.AddBorderToRegionExample = function ( ) 
{
   Tools.SetLicense ( ) ;

   with ( Leadtools ) 
   {
      with ( Leadtools.Codecs ) {

      var codecs = new RasterCodecs();

      var srcFileName = "Assets\\Image1.cmp";
      var destFileName = "Image1_AddBorderToRegion.bmp";
      var image ;
      // Load the image
      return Tools.AppInstallFolder().getFileAsync(srcFileName).then ( function ( loadFile ) {
         return codecs.loadAsync(LeadStreamFactory.create(loadFile))})
         .then ( function ( img ) {
            image = img ;

            // Posterize the image to decrease the number of colors
            var posterize = new Leadtools.ImageProcessing.Color.PosterizeCommand(16);
            posterize.run(image);

            // Specify a pixel in the upper left of the displayed image
            var pt = LeadPointHelper.create(image.imageWidth / 8, image.imageHeight / 8);

            // Adjust the point in case the view perspective is not TopLeft
            pt = image.pointToImage(RasterViewPerspective.topLeft, pt);

            // Create a border region at this point
            var borderColor = image.getPixelColor(pt.Y, pt.X);
            var lowerColor = RasterColorHelper.create(20, 30, 150);
            var upperColor = RasterColorHelper.create(15, 30, 10);
            image.addBorderToRegion(pt.x, pt.y, borderColor, lowerColor, upperColor, RasterRegionCombineMode.set);

            // Fill the region with blue
            var fill = new Leadtools.ImageProcessing.FillCommand(RasterColorHelper.fromKnownColor(RasterKnownColor.blue));
            fill.run (image);

            // Save the image
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
               var saveStream = LeadStreamFactory.create(saveFile);
         
               return codecs.saveAsync(image, saveStream, RasterImageFormat.bmp, 24)})
                  .then ( function ( ) {

                     image.close();
                     codecs.close();
                  });
         }
      }
   }
[TestMethod]
public async Task AddBorderToRegionExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName = @"Image1_AddBorderToRegion.bmp";

   // Load the image
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // Posterize the image to decrease the number of colors
   PosterizeCommand posterize = new PosterizeCommand(16);
   posterize.Run(image);

   // Specify a pixel in the upper left of the displayed image
   LeadPoint pt = LeadPointHelper.Create(image.ImageWidth / 8, image.ImageHeight / 8);

   // Adjust the point in case the view perspective is not TopLeft
   pt = image.PointToImage(RasterViewPerspective.TopLeft, pt);

   // Create a border region at this point
   RasterColor borderColor = image.GetPixelColor(pt.Y, pt.X);
   RasterColor lowerColor = RasterColorHelper.Create(20, 30, 150);
   RasterColor upperColor = RasterColorHelper.Create(15, 30, 10);
   image.AddBorderToRegion(pt.X, pt.Y, borderColor, lowerColor, upperColor, RasterRegionCombineMode.Set);

   // Fill the region with blue
   FillCommand fill = new FillCommand(RasterColorHelper.FromKnownColor(RasterKnownColor.Blue));
   fill.Run(image);

   // Save the image
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, RasterImageFormat.Bmp, 24);

   image.Dispose();
   codecs.Dispose();
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterImage Class
RasterImage Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.