LEADTOOLS Support
Imaging
Imaging SDK Examples
How To: Create a transparent image by combining a transparent and non-transparent image
#1
Posted
:
Thursday, May 4, 2017 2:31:50 PM(UTC)
Groups: Tech Support
Posts: 366
Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
This project illustrates the use of LEADTOOLS 19 and combining images using the
FeatherAlphaBlendCommand. The FeatherAlphaBlendCommand will combine two images using a transparency (grayscale) mask, whereby the mask indicates how much of each image to use in the final output. For non-tranparent images, this process is fairly straight forward. You pass two images you want to combine to the FeatherAlphaBlendCommand along with a third image that indicates how this should be done. You'll also pass a rectangle to indicate where part of the source image will be copied to the destination image using a rectangle, and you will also pass a point to indicate where in the destination image the combining should start.
The FeatherAlphaBlendCommand does not take the alpha channel into consideration when combining images. When dealing with a source image using transparency, special considerations are needed to create transparent output. This considerations include combining the alpha channels of both images and applying the combined output as the alpha image for the destination image.
This example uses image viewers to visually illustrate each image in the process to better understand each step in the process. The combining code in the example is the following:
Code:
if ((SourceViewer.Image.BitsPerPixel != SourceMaskViewer.Image.BitsPerPixel) || (SourceViewer.Image.BitsPerPixel != DestViewer.Image.BitsPerPixel))
{
ColorResolutionCommand colorRes = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 32, RasterByteOrder.Bgr,
RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.None, null);
colorRes.Run(SourceViewer.Image);
colorRes.Run(SourceMaskViewer.Image);
colorRes.Run(DestViewer.Image);
}
LeadRect destRect = new LeadRect((DestViewer.Image.Width - SourceViewer.Image.Width) - 1, (DestViewer.Image.Height - SourceViewer.Image.Height) - 1,
SourceViewer.Image.Width - 1, SourceViewer.Image.Height - 1);
FeatherAlphaBlendCommand blendCmd = new FeatherAlphaBlendCommand(SourceViewer.Image, new LeadPoint(0, 0), destRect, SourceMaskViewer.Image);
blendCmd.Progress += new EventHandler<RasterCommandProgressEventArgs>(blendCmd_Progress);
blendCmd.Run(DestViewer.Image);
DestViewer.Image.SetAlphaImage(CombineMaskViewer.Image.Clone());
This project illustrates using the FeatherAlphaBlendCommand as well as combining the alpha channels to produce a transparent output images. Sample images are included for proper illustration. Here's a snapshot of the application:
See also:
V19 HOWTO: Simple change to alpha mask to produce smooth blendingUpdate: Here is an updated
FeatherAlphaBlendCommand project with project configurations for LEADTOOLS 18, 19, and 20:
Edited by user Monday, May 7, 2018 9:54:25 AM(UTC)
| Reason: Added project with 18/19/20 configurations
Walter Bates
Senior Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Examples
How To: Create a transparent image by combining a transparent and non-transparent image
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.