LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

AddColorRgbRangeToRegion Method

Example 





Specifies the minimum (inclusive) R, G and B values. A pixel must have R,G, and B all greater than or equal to lowerColor and less than or equal to upperColor to be included in the region.
Specifies the maximum (inclusive) R, G and B values. A pixel must have R,G, and B all greater than or equal to lowerColor and less than or equal to upperColor to be included in the region.
The action to take regarding the existing image region, if one is defined.
Creates or updates the image region by adding a region that consists of all the pixels that fall in the given RGB color range. .NET support Silverlight support WinRT support
Syntax
public void AddColorRgbRangeToRegion( 
   RasterColor lowerColor,
   RasterColor upperColor,
   RasterRegionCombineMode combineMode
)
'Declaration
 
Public Sub AddColorRgbRangeToRegion( _
   ByVal lowerColor As RasterColor, _
   ByVal upperColor As RasterColor, _
   ByVal combineMode As RasterRegionCombineMode _
) 
'Usage
 
Dim instance As RasterImage
Dim lowerColor As RasterColor
Dim upperColor As RasterColor
Dim combineMode As RasterRegionCombineMode
 
instance.AddColorRgbRangeToRegion(lowerColor, upperColor, combineMode)
public void AddColorRgbRangeToRegion( 
   RasterColor lowerColor,
   RasterColor upperColor,
   RasterRegionCombineMode combineMode
)
 function Leadtools.RasterImage.AddColorRgbRangeToRegion( 
   lowerColor ,
   upperColor ,
   combineMode 
)
public:
void AddColorRgbRangeToRegion( 
   RasterColor lowerColor,
   RasterColor upperColor,
   RasterRegionCombineMode combineMode
) 

Parameters

lowerColor
Specifies the minimum (inclusive) R, G and B values. A pixel must have R,G, and B all greater than or equal to lowerColor and less than or equal to upperColor to be included in the region.
upperColor
Specifies the maximum (inclusive) R, G and B values. A pixel must have R,G, and B all greater than or equal to lowerColor and less than or equal to upperColor to be included in the region.
combineMode
The action to take regarding the existing image region, if one is defined.
Remarks

This method uses the RGB color model to set a region based on a color range.

To be added to the region a color must fall in the range lowerColor..upperColor. To set a region for all pure red, specify lowerColor and upperColor as follows:

            lowerColor RGB(1,0,0)
            upperColor RGB(255,0,0)
            

Note that this would fail to include many colors that look red to the eye (like RGB(255,4,4)).

This method supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical Imaging editions.

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 AddColorRgbRangeToRegionExample()
      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_AddColorRgbRangeToRegion.bmp")

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

      ' Add the region
      Dim lowerColor As RasterColor = New RasterColor(0, 1, 0)
      Dim upperColor As RasterColor = New RasterColor(0, 255, 0)

      image.AddColorRgbRangeToRegion(lowerColor, upperColor, 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()
      codecs.Dispose()
   End Sub

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

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

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

      // Add the region
      RasterColor lowerColor = new RasterColor(0, 1, 0);
      RasterColor upperColor = new RasterColor(0, 255, 0);

      image.AddColorRgbRangeToRegion(lowerColor, upperColor, 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();
      codecs.Dispose();
   }

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

   with ( Leadtools ) 
   {
      with ( Leadtools.Codecs ) 
      {
         var codecs = new RasterCodecs();

         var srcFileName = "Assets\\Image1.cmp";
         var destFileName = "Image1_AddColorRgbRangeToRegion.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;

            // Add the region
            var lowerColor = RasterColorHelper.create(0, 1, 0);
            var upperColor = RasterColorHelper.create(0, 255, 0);

            image.addColorRgbRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.set);

            // Draw something on the image
            var command = new Leadtools.ImageProcessing.Color.InvertCommand();

            command.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 AddColorRgbRangeToRegionExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName = @"Image1_AddColorRgbRangeToRegion.bmp";

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

   // Add the region
   RasterColor lowerColor = RasterColorHelper.Create(0, 1, 0);
   RasterColor upperColor = RasterColorHelper.Create(0, 255, 0);

   image.AddColorRgbRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.Set);

   // Draw something on the image
   InvertCommand command = new InvertCommand();
   command.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();
}
public void AddColorRgbRangeToRegionExample(RasterImage image, Stream destStream)
{
   // Add the region
   RasterColor lowerColor = new RasterColor(0, 1, 0);
   RasterColor upperColor = new RasterColor(0, 255, 0);
   image.AddColorRgbRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.Set);

   // Draw something on the image
   InvertCommand command = new InvertCommand();
   command.Run(image);

   // Save the image
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, destStream, RasterImageFormat.Png, 24);

   image.Dispose();
}
Public Sub AddColorRgbRangeToRegionExample(ByVal image As RasterImage, ByVal destStream As Stream)
   ' Add the region
   Dim lowerColor As RasterColor = New RasterColor(0, 1, 0)
   Dim upperColor As RasterColor = New RasterColor(0, 255, 0)
   image.AddColorRgbRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.Set)

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

   ' Save the image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, destStream, RasterImageFormat.Png, 24)

   image.Dispose()
End Sub
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
Gray Scale Images
Introduction: Bits Per Pixel and Related Ideas
Using Color Values in LEADTOOLS

 

 


Products | Support | Contact Us | Copyright Notices

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