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



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.
Creates or updates the image region by adding a region that consists of all the pixels that fall in the given RGB color range.

Syntax

Visual Basic (Declaration)  
Public Sub AddColorRgbRangeToRegion( _
   ByVal lowerColor As RasterColor, _
   ByVal upperColor As RasterColor, _
   ByVal combineMode As RasterRegionCombineMode _
) 
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim lowerColor As RasterColor
Dim upperColor As RasterColor
Dim combineMode As RasterRegionCombineMode
 
instance.AddColorRgbRangeToRegion(lowerColor, upperColor, combineMode)
C#  
public void AddColorRgbRangeToRegion( 
   RasterColor lowerColor,
   RasterColor upperColor,
   RasterRegionCombineMode combineMode
)
C++/CLI  
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.

Example

This example will load an image, adds a region corresponding to all colors that have an rgb that includes green but no red and no blue, run the InvertCommand to show the affected area before saving the image back to disk.

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

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
   Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "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()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
public void AddColorRgbRangeToRegionExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "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(); 
   RasterCodecs.Shutdown(); 
}

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.

Requirements

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

See Also