public RasterImage CreateAlphaImage()
Public Function CreateAlphaImage() As RasterImage
- (nullable LTRasterImage *)createAlphaImage:(NSError **)error
public RasterImage createAlphaImage()
public:
RasterImage^ CreateAlphaImage();
The newly create image, which contains the source image alpha channel data.
Only 16-bit, 32-bit, and 64-bit images can have an alpha channel. If the source image has another color resolution, the result is an image filled with zeros.
Typically, the alpha channel contains a mask that is used for transparency.
For more information, refer to Implementing Transparency.
For more information, refer to Grayscale Images.
For more information, refer to Saving A Region.
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 Leadtools.Svg;
public void CreateAlphaImageExample()
{
RasterCodecs codecs = new RasterCodecs();
// Load the image, at 16 bit per pixel.
RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"), 16, CodecsLoadByteOrder.Bgr, 1, 1);
// Specify a rectangle to define the region.
LeadRect ellipseRectangle = new LeadRect(image.Width / 8, image.Height / 8, image.Width / 2, image.Height / 2);
// Create an elliptical region in the AlphaImage.
image.AddEllipseToRegion(null, ellipseRectangle, RasterRegionCombineMode.Set);
// Create a mask image from the region.
RasterImage alphaImage = image.CreateMaskFromRegion();
// Update the alpha channel in the main image.
image.SetAlphaImage(alphaImage);
// Save the image at 16 bits per pixel to keep the alpha channel.
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "TestAlpha.TIF"), RasterImageFormat.Tif, 24, 1, 1, 1, CodecsSavePageMode.Overwrite);
// Load the bitmap that we just saved and get its alpha channel.
image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "TestAlpha.TIF"), 16, CodecsLoadByteOrder.Bgr, 1, 1);
alphaImage = image.CreateAlphaImage();
// Use the AlphaBitmap as a mask to set the region in the MainBitmap.
image.AddMaskToRegion(null, alphaImage, RasterRegionCombineMode.Set);
image.Dispose();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Controls
Imports Leadtools.Dicom
Imports Leadtools.Drawing
Imports Leadtools.Svg
Public Sub CreateAlphaImageExample()
Dim codecs As RasterCodecs = New RasterCodecs()
' Load the image, at 16 bit per pixel.
Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"), 16, CodecsLoadByteOrder.Bgr, 1, 1)
' Specify a rectangle to define the region.
Dim EllipseRectangle As LeadRect = New LeadRect(image.Width \ 8, image.Height \ 8, image.Width \ 2, image.Height \ 2)
' Create an elliptical region in the AlphaImage.
image.AddEllipseToRegion(Nothing, EllipseRectangle, RasterRegionCombineMode.Set)
' Create a mask image from the region.
Dim alphaImage As RasterImage = image.CreateMaskFromRegion()
' Update the alpha channel in the main image.
image.SetAlphaImage(alphaImage)
' Save the image at 16 bits per pixel to keep the alpha channel.
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "TestAlpha.TIF"), RasterImageFormat.Tif, 24, 1, 1, 1, CodecsSavePageMode.Overwrite)
' Load the bitmap that we just saved and get its alpha channel.
image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "TestAlpha.TIF"), 16, CodecsLoadByteOrder.Bgr, 1, 1)
alphaImage = image.CreateAlphaImage()
' Use the AlphaBitmap as a mask to set the region in the MainBitmap.
image.AddMaskToRegion(Nothing, alphaImage, RasterRegionCombineMode.Set)
image.Dispose()
codecs.Dispose()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"
End Class
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