SetAlphaImage Method (original) (raw)
Summary
Replaces existing alpha channel data or creates new alpha channel data.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (BOOL)setAlphaImage:(LTRasterImage *)alphaImage error:(NSError **)error
Parameters
alphaImage
Source RasterImage which references the image that is used to create or replace the alpha channel data.
Example
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:\LEADTOOLS22\Resources\Images";
}
Leadtools Assembly