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



color
Specifies the color to use for 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 of a specified color.

Syntax

Visual Basic (Declaration)  
Public Sub AddColorToRegion( _
   ByVal color As RasterColor, _
   ByVal combineMode As RasterRegionCombineMode _
) 
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim color As RasterColor
Dim combineMode As RasterRegionCombineMode
 
instance.AddColorToRegion(color, combineMode)
C#  
public void AddColorToRegion( 
   RasterColor color,
   RasterRegionCombineMode combineMode
)
C++/CLI  
public:
void AddColorToRegion( 
   RasterColor color,
   RasterRegionCombineMode combineMode
) 

Parameters

color
Specifies the color to use for 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 all pixels of a specified color. It then fills the region with blue before saving it back to disk.

Visual Basic Copy Code
Public Sub AddColorToRegionExample()
   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_AddColorToRegion.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 Point = New Point(image.ImageWidth \ 8, image.ImageHeight \ 8)

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

   ' Get the color of the specified pixel
   Dim regionColor As RasterColor = image.GetPixelColor(pt.Y, pt.X)

   ' Create a region that includes all pixels of that color
   image.AddColorToRegion(regionColor, RasterRegionCombineMode.Set)

   ' Fill the region with blue
   Dim fill As FillCommand = New FillCommand(RasterColor.FromGdiPlusColor(Color.Blue))
   fill.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 AddColorToRegionExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_AddColorToRegion.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 
   Point pt = new Point(image.ImageWidth / 8, image.ImageHeight / 8); 
 
   // Adjust the point in case the view perspective is not TopLeft 
   pt = image.PointToImage(RasterViewPerspective.TopLeft, pt); 
 
   // Get the color of the specified pixel 
   RasterColor regionColor = image.GetPixelColor(pt.Y, pt.X); 
 
   // Create a region that includes all pixels of that color 
   image.AddColorToRegion(regionColor, RasterRegionCombineMode.Set); 
 
   // Fill the region with blue 
   FillCommand fill = new FillCommand(RasterColor.FromGdiPlusColor(Color.Blue)); 
   fill.Run(image); 
 
   // Save the image 
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24); 
 
   image.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

You can use this method to simulate the use of a transparent color as follows:

  1. Call AddColorToRegion, with the transparent color in the color parameter and RasterRegionCombineMode.SetNot in the combineMode parameter.
  2. Call PaintRegion to paint the resulting region, which includes everything in the image, except the transparent color.

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.

This function does not support signed images.

Requirements

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

See Also