Click or drag to resize

OverlayMaskedCommand Class

Overlay a specified image onto the source image using an 8-bit grayscale mask image to control the transparency of the overlay.
Inheritance Hierarchy
SystemObject
  Atalasoft.Imaging.ImageProcessingImageCommand
    Atalasoft.Imaging.ImageProcessingOverlayMaskedCommand

Namespace:  Atalasoft.Imaging.ImageProcessing
Assembly:  Atalasoft.dotImage (in Atalasoft.dotImage.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
[SerializableAttribute]
public class OverlayMaskedCommand : ImageCommand, 
	ISerializable

The OverlayMaskedCommand type exposes the following members.

Constructors
  NameDescription
Public methodOverlayMaskedCommand
Initializes a new instance of the OverlayMaskedCommand class.
Protected methodOverlayMaskedCommand(SerializationInfo, StreamingContext)
Initializes a new instance of OverlayMaskedCommand.
Public methodOverlayMaskedCommand(AtalaImage, AtalaImage)
Initializes a new instance of %OverlayMaskedCommand% specifying the top image and alpha mask.
Public methodOverlayMaskedCommand(AtalaImage, AtalaImage, Point)
Initializes a new instance of %OverlayMaskedCommand% specifying the top image and alpha mask and position of the top image.
Top
Properties
  NameDescription
Public propertyAlphaMask
Gets or sets the 8-bit grayscale image representing the transparency mask of the overlay.
Public propertyApplyToAnyPixelFormat
Reports whether or not this command will be applied to any supplied PixelFormat image
(Inherited from ImageCommand.)
Public propertyCanApplyToAnyPixelFormat
Returns true if the command can be applied to any PixelFormat.
(Inherited from ImageCommand.)
Public propertyInPlaceProcessing
Gets a value indicating whether the command returns a new image or modified the source image passed into the command.
(Overrides ImageCommandInPlaceProcessing.)
Public propertyPosition
Gets or sets the position of the top image onto the source image.
Public propertyProgress
Gets or sets the ProgressEventHandler delegate which can be used to view or cancel the progress of the current process.
(Inherited from ImageCommand.)
Public propertySupportedPixelFormats
Returns an array of PixelFormats supported by this command.
(Overrides ImageCommandSupportedPixelFormats.)
Public propertyTopImage
Gets or sets the image that will be overlayed onto the source image.
Top
Methods
  NameDescription
Public methodApply
Apply the command to the given image.
(Inherited from ImageCommand.)
Public methodApplyToImage Obsolete.
Applies the command to the source AtalaImage.
(Inherited from ImageCommand.)
Protected methodConstructChangedSourceImage
The method is called by the default implementation of Apply. It determines if it is necessary to create a copy of the source image in a different pixel format and if so, determines the best new pixel format and allocates that image.
(Inherited from ImageCommand.)
Protected methodConstructFinalImage
Called by the default implementation of Apply, ConstructFinalImage constructs the image that will be used as the destination image for the command.
(Inherited from ImageCommand.)
Protected methodConstructImageResults
Constructs the results object for this command.
(Inherited from ImageCommand.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Protected methodGetChangedPixelFormat
This method is called to change the pixel format of the source image.
(Inherited from ImageCommand.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetObjectData
Populates a SerializationInfo with the data needed to serialize the target object.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodImageCommandGetObjectData
Aggregates ImageCommand data into the supplied SerializationInfo object.
(Inherited from ImageCommand.)
Public methodIsPixelFormatSupported
Returns a value indicating if the specified pixel format is supported.
(Inherited from ImageCommand.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodPerformActualCommand
Performs the actual command.
(Overrides ImageCommandPerformActualCommand(AtalaImage, AtalaImage, Rectangle, ImageResults).)
Protected methodSelectBestAlternatePixelFormat
Choose the best pixel format to use for this command when the supplied source image's pixel format is unacceptable.
(Inherited from ImageCommand.)
Protected methodSelectPreferredPixelFormat
Chooses a pixel format that is preferred for this command.
(Inherited from ImageCommand.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Protected methodVerifyImage
Verify the integrity of an AtalaImage.
(Inherited from ImageCommand.)
Protected methodVerifyProperties
Verify the integrity of properties in the command before processing an image.
(Overrides ImageCommandVerifyProperties(AtalaImage).)
Top
Remarks

If the top image already contains an alpha channel, use OverlayCommand, which will alpha blend the images automatically.

The bottom image must be a continuous format, such as 8-bit grayscale or 24-bit RGB. See OverlayMaskedDocumentCommand for masking 1-bit binary images.

This command processes the source image in-place, and ApplyToImage always returns null.

Examples
OverlayMasked (C#)
private AtalaImage OverlayImage(string bottomFile, string topFile, string maskFile)
{
    // Make sure the files exist.
    if (!File.Exists(bottomFile))
        throw new FileNotFoundException("The bottom image file could not be found.", bottomFile);

    if (!File.Exists(topFile))
        throw new FileNotFoundException("The file to overlay could not be found.", topFile);

    if (!File.Exists(maskFile))
        throw new FileNotFoundException("The mask file could not be found.", maskFile);

    // Load the bottom image.
    AtalaImage tmpImage = new AtalaImage(bottomFile);

    // Overlay does not support 4-bit bottom images.
    AtalaImage bottomImage = null;
    if (tmpImage.PixelFormat == PixelFormat.Pixel4bppIndexed)
    {
        bottomImage = tmpImage.GetChangedPixelFormat(PixelFormat.Pixel8bppIndexed);
        tmpImage.Dispose();
    }
    else
        bottomImage = tmpImage;

    // Load the top image.
    tmpImage = new AtalaImage(topFile);

    // If the bottom image is 16-bit per component, the top image must be the same.
    AtalaImage topImage = null;
    if (AtalaImage.PixelFormatIsTwoBytePerComponent(bottomImage.PixelFormat) && topImage.PixelFormat != bottomImage.PixelFormat)
    {
        topImage = tmpImage.GetChangedPixelFormat(bottomImage.PixelFormat);
        tmpImage.Dispose();
    }
    else
        topImage = tmpImage;

    // Load the mask image that will describe the alpha values.
    tmpImage = new AtalaImage(maskFile);

    // The mask must be 8-bit grayscale.
    AtalaImage mask = null;
    if (tmpImage.PixelFormat != PixelFormat.Pixel8bppGrayscale)
    {
        mask = tmpImage.GetChangedPixelFormat(PixelFormat.Pixel8bppGrayscale);
        tmpImage.Dispose();
    }
    else
        mask = tmpImage;

    // The mask must also be the same size as the top image.
    if (mask.Size != topImage.Size)
    {
        ResampleCommand resample = new ResampleCommand(topImage.Size);
        tmpImage = resample.ApplyToImage(mask);
        mask.Dispose();
        mask = tmpImage;
    }

    OverlayMaskedCommand cmd = new OverlayMaskedCommand(topImage, mask);
    cmd.ApplyToImage(bottomImage);

    // We are done with the top image and mask.
    topImage.Dispose();
    mask.Dispose();

    return bottomImage;
}
OverlayMaskedVB (Visual Basic)
Private Function OverlayImage(ByVal bottomFile As String, ByVal topFile As String, ByVal maskFile As String) As AtalaImage
    ' Make sure the files exist.
    If Not File.Exists(bottomFile) Then
        Throw New FileNotFoundException("The bottom image file could not be found.", bottomFile)
    End If

    If Not File.Exists(topFile) Then
        Throw New FileNotFoundException("The file to overlay could not be found.", topFile)
    End If

    If Not File.Exists(maskFile) Then
        Throw New FileNotFoundException("The mask file could not be found.", maskFile)
    End If

    ' Load the bottom image.
    Dim tmpImage As AtalaImage =  New AtalaImage(bottomFile) 

    ' Overlay does not support 4-bit bottom images.
    Dim bottomImage As AtalaImage =  Nothing 
    If tmpImage.PixelFormat = PixelFormat.Pixel4bppIndexed Then
        bottomImage = tmpImage.GetChangedPixelFormat(PixelFormat.Pixel8bppIndexed)
        tmpImage.Dispose()
    Else 
        bottomImage = tmpImage
    End If

    ' Load the top image.
    tmpImage = New AtalaImage(topFile)

    ' If the bottom image is 16-bit per component, the top image must be the same.
    Dim topImage As AtalaImage =  Nothing 
    If AtalaImage.PixelFormatIsTwoBytePerComponent(bottomImage.PixelFormat) And topImage.PixelFormat <> bottomImage.PixelFormat Then
        topImage = tmpImage.GetChangedPixelFormat(bottomImage.PixelFormat)
        tmpImage.Dispose()
    Else 
        topImage = tmpImage
    End If

    ' Load the mask image that will describe the alpha values.
    tmpImage = New AtalaImage(maskFile)

    ' The mask must be 8-bit grayscale.
    Dim mask As AtalaImage =  Nothing 
    If tmpImage.PixelFormat <> PixelFormat.Pixel8bppGrayscale Then
        mask = tmpImage.GetChangedPixelFormat(PixelFormat.Pixel8bppGrayscale)
        tmpImage.Dispose()
    Else 
        mask = tmpImage
    End If

    ' The mask must also be the same size as the top image.
    If mask.Size <> topImage.Size Then
        Dim resample As ResampleCommand =  New ResampleCommand(topImage.Size) 
        tmpImage = resample.ApplyToImage(mask)
        mask.Dispose()
        mask = tmpImage
    End If

    Dim cmd As OverlayMaskedCommand =  New OverlayMaskedCommand(topImage,mask) 
    cmd.ApplyToImage(bottomImage)

    ' We are done with the top image and mask.
    topImage.Dispose()
    mask.Dispose()

    Return bottomImage
End Function
See Also

Reference

OverlayCommand
OverlayMaskedCommand
OverlayMaskedDocumentCommand Class