LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

AddColorToRegion Method

Example 





Specifies the color to use for 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 of a specified color. .NET support Silverlight support WinRT support
Syntax
public void AddColorToRegion( 
   RasterColor color,
   RasterRegionCombineMode combineMode
)
'Declaration
 
Public Sub AddColorToRegion( _
   ByVal color As RasterColor, _
   ByVal combineMode As RasterRegionCombineMode _
) 
'Usage
 
Dim instance As RasterImage
Dim color As RasterColor
Dim combineMode As RasterRegionCombineMode
 
instance.AddColorToRegion(color, combineMode)
public void AddColorToRegion( 
   RasterColor color,
   RasterRegionCombineMode combineMode
)
 function Leadtools.RasterImage.AddColorToRegion( 
   color ,
   combineMode 
)
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.
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 Leadtools.Drawing.RasterImagePainter.PaintRegion(Leadtools.RasterImage,System.IntPtr,Leadtools.LeadRect,Leadtools.LeadRect,Leadtools.LeadRect,Leadtools.LeadRect,Leadtools.Drawing.RasterPaintProperties) 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.

Example
 
Public Sub AddColorToRegionExample()
      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_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 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)

      ' 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.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 AddColorToRegionExample()
   {
      RasterCodecs codecs = new RasterCodecs();

      string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
      string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "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
      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);

      // 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.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.AddColorToRegionExample = function()
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

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

               // Get the color of the specified pixel
               var 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
               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 AddColorToRegionExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName = @"Image1_AddColorToRegion.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);

   // 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(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();
}
public void AddColorToRegionExample(RasterImage image, Stream destStream)
{
   // 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);

   // 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(RasterColorConverter.FromColor(Colors.Blue));
   fill.Run(image);

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

   image.Dispose();
}
Public Sub AddColorToRegionExample(ByVal image As RasterImage, ByVal destStream As Stream)
   ' 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)

   ' 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(RasterColorConverter.FromColor(Colors.Blue))
   fill.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.