public void SetAlphaImage(
RasterImage alphaImage
)
- (BOOL)setAlphaImage:(LTRasterImage *)alphaImage error:(NSError **)error
public void setAlphaImage(RasterImage alphaImage)
public:
void SetAlphaImage(
RasterImage^ alphaImage
)
def SetAlphaImage(self,alphaImage):
alphaImage
Source RasterImage which references the image that is used to create or replace the alpha channel data.
Typically, an alpha channel contains a mask that is used for transparency. This method, together with CreateAlphaImage and the LEADTOOLS region processing methods, lets you use the alpha channel to implement transparency.
Only 16-bit, 32-bit and 64-bit images can have an alpha channel. If the image is of any other color resolution, this method converts the image to 32-bit before it replaces the alpha channel. (If you want 16-bit, you should change it using ColorResolutionCommand, if necessary, before calling this method.)
For 64-bit images, the alphaImage parameter is converted to 16 bit grayscale before replacing the alpha channel. If the image is 48-bit, it will be converted to 64-bit and then have the alpha information added to it.
The alphaImage parameter does not have to be grayscale. This method converts the data from the alphaImage parameter to the necessary grayscale or 1-bit format as it replaces the alpha channel in the image. (The alphaImage, itself, remains unchanged.)
This method does not support signed images.
For more information, refer to Implementing Transparency.
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:\LEADTOOLS23\Resources\Images";
}
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.imageprocessing.core.*;
import leadtools.svg.*;
import leadtools.imageprocessing.CloneCommand;
import leadtools.imageprocessing.FillCommand;
import leadtools.imageprocessing.FlipCommand;
import leadtools.imageprocessing.GrayscaleCommand;
import leadtools.imageprocessing.color.InvertCommand;
import leadtools.imageprocessing.color.PosterizeCommand;
public void createAlphaImageExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
RasterCodecs codecs = new RasterCodecs();
// Load the image, at 16 bit per pixel.
RasterImage image = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "IMAGE1.CMP"), 16, CodecsLoadByteOrder.BGR, 1, 1);
String destFileName = combine(LEAD_VARS_IMAGES_DIR, "TestAlpha.TIF");
// Specify a rectangle to define the region.
LeadRect ellipseRectangle = new LeadRect(image.getWidth() / 8, image.getHeight() / 8, image.getWidth() / 2,
image.getHeight() / 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, destFileName, RasterImageFormat.TIF, 24, 1, 1, 1, CodecsSavePageMode.OVERWRITE);
// Load the bitmap that we just saved and get its alpha channel.
image = codecs.load(destFileName, 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);
// Clean up
image.dispose();
codecs.dispose();
assertTrue("file unsuccessfully saved to " + destFileName, (new File(destFileName)).exists());
System.out.printf("File saved successfully to %s%n", destFileName);
}
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