Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.6.28
|
Leadtools Namespace > RasterImage Class : CreateAlphaImage Method |
public RasterImage CreateAlphaImage()
'Declaration
Public Function CreateAlphaImage() As RasterImage
'Usage
Dim instance As RasterImage Dim value As RasterImage value = instance.CreateAlphaImage()
public RasterImage CreateAlphaImage()
- (nullable LTRasterImage *)createAlphaImage:(NSError **)error
public RasterImage createAlphaImage()
function Leadtools.RasterImage.CreateAlphaImage()
public: RasterImage^ CreateAlphaImage();
Only 16-, 32-, 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.
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:\Users\Public\Documents\LEADTOOLS Images" End Class
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(ImagesPath.Path, "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(ImagesPath.Path, "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(ImagesPath.Path,"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(); }
RasterImageExamples.prototype.CreateAlphaImageExample = function ( ) { Tools.SetLicense ( ) ; with (Leadtools) { with (Leadtools.Codecs) { var codecs = new RasterCodecs(); // Load the image, at 16 bit per pixel. var srcFileName = "Assets\\Image1.cmp"; var image; return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) { return codecs.loadAsync(LeadStreamFactory.create(loadFile), 16, CodecsLoadByteOrder.bgr, 1, 1) }) .then(function (img) { image = img; // Specify a rectangle to define the region. var ellipseRectangle = LeadRectHelper.create(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. var 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. return Tools.AppLocalFolder().createFileAsync("TestAlpha.TIF") }) .then(function (saveFile) { var saveStream = LeadStreamFactory.create(saveFile); return codecs.saveAsync(image, saveStream, RasterImageFormat.tif, 24, 1, 1, 1, CodecsSavePageMode.overwrite) }) .then(function () { image.close(); // Load the bitmap that we just saved and get its alpha channel. srcFileName = "TestAlpha.TIF"; return Tools.AppLocalFolder().getFileAsync(srcFileName) }) .then(function (loadFile) { return codecs.loadAsync(LeadStreamFactory.create(loadFile), 16, CodecsLoadByteOrder.bgr, 1, 1) }) .then(function (img) { image = img; alphaImage = image.createAlphaImage(); // Use the AlphaBitmap as a mask to set the region in the MainBitmap. image.addMaskToRegion(null, alphaImage, RasterRegionCombineMode.set); console.assert(image.hasRegion, "image.HasRegion"); image.close(); codecs.close(); }); } } }
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Core; using Leadtools.ImageProcessing.Color; using Leadtools.Dicom; public async Task CreateAlphaImageExample() { RasterCodecs codecs = new RasterCodecs(); // Load the image, at 16 bit per pixel. string srcFileName = @"Assets\Image1.cmp"; StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 16, CodecsLoadByteOrder.Bgr, 1, 1); // Specify a rectangle to define the region. LeadRect ellipseRectangle = LeadRectHelper.Create(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. StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("TestAlpha.TIF"); ILeadStream saveStream = LeadStreamFactory.Create(saveFile); await codecs.SaveAsync(image, saveStream, RasterImageFormat.Tif, 24, 1, 1, 1, CodecsSavePageMode.Overwrite); image.Dispose(); // Load the bitmap that we just saved and get its alpha channel. srcFileName = @"TestAlpha.TIF"; image = await codecs.LoadAsync(saveStream, 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); Assert.IsTrue(image.HasRegion); image.Dispose(); codecs.Dispose(); }
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 CreateAlphaImageExample(RasterImage image, Stream destStream) { RasterCodecs codecs = new RasterCodecs(); // Specify a rectangle to define the region. LeadRect EllipseRectangle = new LeadRect(image.Width / 8, image.Height / 8, image.Width / 2, image.Height / 2); // Create a region in the AlphaImage. image.AddRectangleToRegion(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, destStream, RasterImageFormat.Tif, 24, 1, 1, 1, CodecsSavePageMode.Overwrite); // Load the bitmap that we just saved and get its alpha channel. image = codecs.Load(destStream, 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(); }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Dicom Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Core Imports Leadtools.ImageProcessing.Color Imports Leadtools.Windows.Media Public Sub CreateAlphaImageExample(ByVal image As RasterImage, ByVal destStream As Stream) Dim codecs As RasterCodecs = New RasterCodecs() ' 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 a region in the AlphaImage. image.AddRectangleToRegion(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, destStream, RasterImageFormat.Tif, 24, 1, 1, 1, CodecsSavePageMode.Overwrite) ' Load the bitmap that we just saved and get its alpha channel. image = codecs.Load(destStream, 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() End Sub