Click or drag to resize

OverlayCommand Class

Summary description for tmpOverlay.
Overlays a specified image on top of the source image.
Inheritance Hierarchy
SystemObject
  Atalasoft.Imaging.ImageProcessingImageCommand
    Atalasoft.Imaging.ImageProcessingOverlayCommand

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 OverlayCommand : ImageCommand, 
	ISerializable

The OverlayCommand type exposes the following members.

Constructors
  NameDescription
Public methodOverlayCommand
Initializes a new instance of the OverlayCommand class.
Protected methodOverlayCommand(SerializationInfo, StreamingContext)
Initializes a new instance of %OverlayCommand%.
Public methodOverlayCommand(AtalaImage, Point)
Overlay one image onto another.
Public methodOverlayCommand(AtalaImage, Point, Double)
Overlay one image onto another.
Public methodOverlayCommand(AtalaImage, Point, Color)
Overlay one image onto another.
Public methodOverlayCommand(AtalaImage, Point, Int32)
Overlay an 8-bit image onto another.
Top
Properties
  NameDescription
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 propertyOpacity
Gets or sets the opacity of the top image.
Public propertyPosition
Gets or sets the position of the top image with respect to 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.
Public propertyTransparentColor
Gets or sets the color that will be used as a transparent mask for the top image.
Public propertyTransparentIndex
Gets or sets the palette index that will be used as a transparent mask for the top 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
Verifies the properties.
(Overrides ImageCommandVerifyProperties(AtalaImage).)
Top
Remarks

If the top image has an alpha channel, that alpha will be used to control the transparency of the overlay and will override the %TransparentColor% and %Opacity% values.

When overlaying one image with alpha, on top of another image with alpha, the alpha channels will be merged to take the maximum pixel value of each alpha channel. See OverlayMergedCommand for more specific options.

The top image will always be converted to the pixel format of the bottom image, unless the top image has an alpha channel, which it will then use for alpha blending.

This command supports all pixel formats with the exception of 4-bit Indexed.

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

Examples
OverlayCommand (C#)
private AtalaImage OverlayImage(string bottomFile, string topFile, Point position)
{
    // 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);

    // 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;

    OverlayCommand cmd = new OverlayCommand(topImage, position);
    cmd.ApplyToImage(bottomImage);

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

    return bottomImage;
}
OverlayCommandVB (Visual Basic)
Private Function OverlayImage(ByVal bottomFile As String, ByVal topFile As String, ByVal position As Point) 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

    ' 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

    Dim cmd As OverlayCommand =  New OverlayCommand(topImage,position) 
    cmd.ApplyToImage(bottomImage)

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

    Return bottomImage
End Function
See Also

Reference

OverlayMergedCommand
OverlayMaskedCommand