OverlayMaskedCommand Class |
Namespace: Atalasoft.Imaging.ImageProcessing
The OverlayMaskedCommand type exposes the following members.
Name | Description | |
---|---|---|
OverlayMaskedCommand |
Initializes a new instance of the OverlayMaskedCommand class.
| |
OverlayMaskedCommand(SerializationInfo, StreamingContext) | Initializes a new instance of OverlayMaskedCommand. | |
OverlayMaskedCommand(AtalaImage, AtalaImage) | Initializes a new instance of %OverlayMaskedCommand% specifying the top image and alpha mask. | |
OverlayMaskedCommand(AtalaImage, AtalaImage, Point) | Initializes a new instance of %OverlayMaskedCommand% specifying the top image and alpha mask and position
of the top image. |
Name | Description | |
---|---|---|
AlphaMask | Gets or sets the 8-bit grayscale image representing the transparency mask of the overlay. | |
ApplyToAnyPixelFormat | Reports whether or not this command will be applied to any supplied PixelFormat image (Inherited from ImageCommand.) | |
CanApplyToAnyPixelFormat | Returns true if the command can be applied to any PixelFormat. (Inherited from ImageCommand.) | |
InPlaceProcessing | Gets a value indicating whether the command returns a new image or modified the source image passed into
the command. (Overrides ImageCommandInPlaceProcessing.) | |
Position | Gets or sets the position of the top image onto the source image. | |
Progress | Gets or sets the ProgressEventHandler delegate which can be used to view or cancel the
progress of the current process. (Inherited from ImageCommand.) | |
SupportedPixelFormats | Returns an array of PixelFormats supported by this command. (Overrides ImageCommandSupportedPixelFormats.) | |
TopImage | Gets or sets the image that will be overlayed onto the source image. |
Name | Description | |
---|---|---|
Apply | Apply the command to the given image. (Inherited from ImageCommand.) | |
ApplyToImage | Obsolete.
Applies the command to the source AtalaImage.
(Inherited from ImageCommand.) | |
ConstructChangedSourceImage | 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.) | |
ConstructFinalImage | 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.) | |
ConstructImageResults | Constructs the results object for this command. (Inherited from ImageCommand.) | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetChangedPixelFormat | This method is called to change the pixel format of the source image. (Inherited from ImageCommand.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetObjectData |
Populates a SerializationInfo with the data needed to serialize the target object.
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
ImageCommandGetObjectData | Aggregates ImageCommand data into the supplied SerializationInfo object. (Inherited from ImageCommand.) | |
IsPixelFormatSupported | Returns a value indicating if the specified pixel format is supported. (Inherited from ImageCommand.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
PerformActualCommand |
Performs the actual command.
(Overrides ImageCommandPerformActualCommand(AtalaImage, AtalaImage, Rectangle, ImageResults).) | |
SelectBestAlternatePixelFormat | Choose the best pixel format to use for this command when the supplied source image's pixel format is
unacceptable. (Inherited from ImageCommand.) | |
SelectPreferredPixelFormat | Chooses a pixel format that is preferred for this command. (Inherited from ImageCommand.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
VerifyImage | Verify the integrity of an AtalaImage. (Inherited from ImageCommand.) | |
VerifyProperties |
Verify the integrity of properties in the command before processing an image.
(Overrides ImageCommandVerifyProperties(AtalaImage).) |
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.
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; }
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