Creates or updates the image region by adding a region that consists of all the pixels of a specified color.
public void AddColorToRegion(Leadtools.RasterColor color,Leadtools.RasterRegionCombineMode combineMode)
Public Sub AddColorToRegion( _ByVal color As Leadtools.RasterColor, _ByVal combineMode As Leadtools.RasterRegionCombineMode _)
public void AddColorToRegion(Leadtools.RasterColor color,Leadtools.RasterRegionCombineMode combineMode)
- (BOOL)addColorToRegion:(LTRasterColor *)colorcombineMode:(LTRasterRegionCombineMode)combineModeerror:(NSError **)error
public void addColorToRegion(RasterColor color,RasterRegionCombineMode combineMode)
function Leadtools.RasterImage.AddColorToRegion(color ,combineMode)
public:void AddColorToRegion(Leadtools.RasterColor color,Leadtools.RasterRegionCombineMode combineMode)
color
Specifies the color to use for the region.
combineMode
The action to take regarding the existing image region, if one is defined.
You can use this method to simulate the use of a transparent color as follows:
To update an existing region, specify how the new region is to be combined with the existing one using the combineMode parameter. For more information, refer to RasterRegionCombineMode.
The AddColorToRegion function can use the Extended Grayscale mask. For more information, refer to Grayscale Images
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 method supports unsigned data images, but not signed ones.
In the Document and Medical toolkits, the COLORREF value can represent a 16 bit grayscale value if RasterImage is a 12 or 16-bit grayscale bitmap. To avoid confusion with an RGB value, set the COLORREF_GRAY16 mask (0x04000000). In this case (0x0400YYYY), the lower 16 bits (0xYYYY) of the COLORREF value represent the 16-bit grayscale value. (0x0400FFFF is 16-bit white and 0x04000000 is 16-bit black.) This is not a standard Windows value. Therefore, although LEADTOOLS methods will recognize a COLORREF having this format, but Windows methods will not.
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.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Core;using Leadtools.ImageProcessing.Color;using Leadtools.Dicom;using Leadtools.Drawing;using Leadtools.Controls;using LeadtoolsExamples.Common;using Leadtools.Svg;public void AddColorToRegionExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");string destFileName = Path.Combine(ImagesPath.Path, "Image1_AddColorToRegion.bmp");// Load the imageRasterImage image = codecs.Load(srcFileName);// Posterize the image to decrease the number of colorsPosterizeCommand posterize = new PosterizeCommand(16);posterize.Run(image);// Specify a pixel in the upper left of the displayed imageLeadPoint pt = new LeadPoint(image.ImageWidth / 8, image.ImageHeight / 8);// Adjust the point in case the view perspective is not TopLeftpt = image.PointToImage(RasterViewPerspective.TopLeft, pt);// Get the color of the specified pixelRasterColor regionColor = image.GetPixelColor(pt.Y, pt.X);// Create a region that includes all pixels of that colorimage.AddColorToRegion(regionColor, RasterRegionCombineMode.Set);// Fill the region with blueFillCommand fill = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Blue));fill.Run(image);// Save the imagecodecs.Save(image, destFileName, RasterImageFormat.Bmp, 24);image.Dispose();codecs.Dispose();}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.CoreImports Leadtools.ImageProcessing.ColorImports Leadtools.ControlsImports Leadtools.DicomImports Leadtools.DrawingImports Leadtools.SvgPublic 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 imageDim image As RasterImage = codecs.Load(srcFileName)' Posterize the image to decrease the number of colorsDim posterize As PosterizeCommand = New PosterizeCommand(16)posterize.Run(image)' Specify a pixel in the upper left of the displayed imageDim pt As LeadPoint = New LeadPoint(image.ImageWidth \ 8, image.ImageHeight \ 8)' Adjust the point in case the view perspective is not TopLeftpt = image.PointToImage(RasterViewPerspective.TopLeft, pt)' Get the color of the specified pixelDim regionColor As RasterColor = image.GetPixelColor(pt.Y, pt.X)' Create a region that includes all pixels of that colorimage.AddColorToRegion(regionColor, RasterRegionCombineMode.Set)' Fill the region with blueDim fill As FillCommand = New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Blue))fill.Run(image)' Save the imagecodecs.Save(image, destFileName, RasterImageFormat.Bmp, 24)image.Dispose()codecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Dicom;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Core;using Leadtools.ImageProcessing.Color;using Leadtools.Examples;using Leadtools.Windows.Media;public void AddColorToRegionExample(RasterImage image, Stream destStream){// Posterize the image to decrease the number of colorsPosterizeCommand posterize = new PosterizeCommand(16);posterize.Run(image);// Specify a pixel in the upper left of the displayed imageLeadPoint pt = new LeadPoint(image.ImageWidth / 8, image.ImageHeight / 8);// Adjust the point in case the view perspective is not TopLeftpt = image.PointToImage(RasterViewPerspective.TopLeft, pt);// Get the color of the specified pixelRasterColor regionColor = image.GetPixelColor(pt.Y, pt.X);// Create a region that includes all pixels of that colorimage.AddColorToRegion(regionColor, RasterRegionCombineMode.Set);// Fill the region with blueFillCommand fill = new FillCommand(RasterColorConverter.FromColor(Colors.Blue));fill.Run(image);// Save the imageRasterCodecs codecs = new RasterCodecs();codecs.Save(image, destStream, RasterImageFormat.Png, 24);image.Dispose();}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.DicomImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.CoreImports Leadtools.ImageProcessing.ColorImports Leadtools.Windows.MediaPublic Sub AddColorToRegionExample(ByVal image As RasterImage, ByVal destStream As Stream)' Posterize the image to decrease the number of colorsDim posterize As PosterizeCommand = New PosterizeCommand(16)posterize.Run(image)' Specify a pixel in the upper left of the displayed imageDim pt As LeadPoint = New LeadPoint(image.ImageWidth / 8, image.ImageHeight / 8)' Adjust the point in case the view perspective is not TopLeftpt = image.PointToImage(RasterViewPerspective.TopLeft, pt)' Get the color of the specified pixelDim regionColor As RasterColor = image.GetPixelColor(pt.Y, pt.X)' Create a region that includes all pixels of that colorimage.AddColorToRegion(regionColor, RasterRegionCombineMode.Set)' Fill the region with blueDim fill As FillCommand = New FillCommand(RasterColorConverter.FromColor(Colors.Blue))fill.Run(image)' Save the imageDim codecs As RasterCodecs = New RasterCodecs()codecs.Save(image, destStream, RasterImageFormat.Png, 24)image.Dispose()End Sub
|
Products |
Support |
Feedback: AddColorToRegion Method - Leadtools |
Introduction |
Help Version 19.0.2017.6.19
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.