Creates a grayscale image from this
RasterImage alpha channel data.
Syntax
Visual Basic (Declaration) |
|
Public Function CreateAlphaImage() As RasterImage |
Visual Basic (Usage) |
Copy Code |
Dim instance As RasterImage
Dim value As RasterImage
value = instance.CreateAlphaImage()
|
Return Value
The newly create image, which contains the source image alpha channel data.
Example
Visual Basic |
Copy Code |
Public Sub CreateAlphaImageExample() RasterCodecs.Startup() Dim codecs As RasterCodecs = New RasterCodecs() Dim image As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP", 16, CodecsLoadByteOrder.Bgr, 1, 1)
Dim EllipseRectangle As Rectangle = New Rectangle(image.Width \ 8, image.Height \ 8, image.Width \ 2, image.Height \ 2)
image.AddEllipseToRegion(Nothing, EllipseRectangle, RasterRegionCombineMode.Set)
Dim alphaImage As RasterImage = image.CreateMaskFromRegion()
image.SetAlphaImage(alphaImage)
codecs.Save(image, LeadtoolsExamples.Common.ImagesPath.Path + "TestAlpha.TIF", RasterImageFormat.Tif, 24, 1, 1, 1, CodecsSavePageMode.Overwrite)
image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "TestAlpha.TIF", 16, CodecsLoadByteOrder.Bgr, 1, 1)
alphaImage = image.CreateAlphaImage()
image.AddMaskToRegion(Nothing, alphaImage, RasterRegionCombineMode.Set)
image.Dispose() codecs.Dispose() RasterCodecs.Shutdown() End Sub |
C# |
Copy Code |
public void CreateAlphaImageExample() { RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); // Load the image, at 16 bit per pixel. RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP", 16, CodecsLoadByteOrder.Bgr, 1, 1); // Specify a rectangle to define the region. Rectangle EllipseRectangle = new Rectangle(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, LeadtoolsExamples.Common.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(LeadtoolsExamples.Common.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(); RasterCodecs.Shutdown(); } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also