Creates a 1-bit mask image from the region that is defined in the image.
public RasterImage CreateMaskFromRegion() Public Function CreateMaskFromRegion() As RasterImage - (nullable LTRasterImage *)createMaskFromRegion:(NSError **)error public RasterImage createMaskFromRegion() public:RasterImage^ CreateMaskFromRegion();
The newly created RasterImage which will be updated with a 1-bit, black-and-white image, where pixels from the region are white, and all others are black.
For more information, refer to Implementing Transparency.
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 example will load an image, sets a color region using black, and then creates a 1-bit mask image from that image and saves it 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 CreateMaskFromRegionExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");string destFileName = Path.Combine(ImagesPath.Path, "Image1_CreateMaskFromRegion.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);RasterImage maskImage = image.CreateMaskFromRegion();codecs.Save(maskImage, destFileName, RasterImageFormat.Bmp, 1);maskImage.Dispose();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 CreateMaskFromRegionExample()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_CreateMaskFromRegion.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)Dim maskImage As RasterImage = image.CreateMaskFromRegion()codecs.Save(maskImage, destFileName, RasterImageFormat.Bmp, 1)maskImage.Dispose()image.Dispose()codecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
c#[Silverlight C# Example]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 CreateMaskFromRegionExample(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);RasterImage maskImage = image.CreateMaskFromRegion();RasterCodecs codecs = new RasterCodecs();codecs.Save(maskImage, destStream, RasterImageFormat.Png, 0);maskImage.Dispose();image.Dispose();}vb[Silverlight VB Example]Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.DicomImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.CoreImports Leadtools.ImageProcessing.ColorImports Leadtools.Windows.MediaPublic Sub CreateMaskFromRegionExample(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)Dim maskImage As RasterImage = image.CreateMaskFromRegion()Dim codecs As RasterCodecs = New RasterCodecs()codecs.Save(maskImage, destStream, RasterImageFormat.Png, 0)maskImage.Dispose()image.Dispose()End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
