Click or drag to resize

UserTransform Class

This allows you to write your own transform methods and add them to the transform chain, just like the built-in transforms. To do this, you must supply a UserTransformCallback.

Inheritance Hierarchy

Namespace:  Atalasoft.Imaging.ImageProcessing.Transforms
Assembly:  Atalasoft.dotImage (in Atalasoft.dotImage.dll) Version: (.NET 4.5.2, x86)
public class UserTransform : Transform

The UserTransform type exposes the following members.

Public methodUserTransform
Creates a new instance of UserTransform.
Public methodUserTransform(UserTransformCallback)
Creates a new instance of the UserTransform class specifying the use transform callback.
Public methodUserTransform(UserTransformCallback, InterpolationMode)
Creates a new instance of the UserTransform class specifying the use transform callback and interpolation mode.
Public methodUserTransform(UserTransformCallback, InterpolationMode, Color)
Creates a new instance of the UserTransform class specifying the use transform callback, interpolation mode, and background color.
Public propertyApplyToAnyPixelFormat
Reports whether or not this command will be applied to any supplied PixelFormat image
(Inherited from ImageCommand.)
Public propertyBackColor
Gets or sets the background color used when a transform uncovers part of the image.
Public propertyCallback
Gets or sets the UserTransformCallback delegate which will be called for each pixel processed in the output image.
Public propertyCanApplyToAnyPixelFormat
Returns true if the command can be applied to any PixelFormat.
(Inherited from ImageCommand.)
Public propertyInPlaceProcessing
Gets a value indicating if the source image data is processed in-place as opposed to returning a new image.
(Inherited from ImageCommand.)
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.
(Inherited from Transform.)
Public propertyTransformMode
Gets or sets the InterpolationMode of this transform.
Public methodAddToChain
Adds this transform to the transforms chain.
(Overrides TransformAddToChain(Int32, Int32).)
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 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
PerformActualCommand does the actual work of the image processing 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 methodSelectCompatibleBackgroundColor
Returns a color value compatible with the image.
(Inherited from Transform.)
Protected methodSelectPreferredPixelFormat
Chooses a pixel format that is preferred for this command.
(Inherited from Transform.)
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.
(Inherited from Transform.)

This method will be called once for each pixel in the output image. You need to set the FromPixel parameter to the pixels (may be fractional) that the input X and Y values will be pulled from. Again, you tell the transform processor where to pull the source pixel from.

Your callback method should be able to handle any kind of input range; inputs may be outside the image rectangle, if you are chaining transforms. Likewise, your function can output values that are outside the image rectangle. If your function is the last in the chain, values outside the image rect will be set to the background color.

This method requires a continuous tone image. If the source image is not continuous, it will attempt to convert the image into one.

UserTransform Example (C#)
private void menuUserTransform_Click(object sender, System.EventArgs e)
    // Load a 24-bit image.
    AtalaImage image = new AtalaImage(@"D:\Test Images\1.jpg");

    // Apply the our own transform.
    UserTransform cmd = new UserTransform(new UserTransformCallback(UserCallback));
    AtalaImage result = cmd.Apply(image).Image;

    // Display the result in a WorkspaceViewer.
    this.viewer.Image = result;

private bool UserCallback(UserTransformData data)
    // This will take small blocks from the image and rearrange them.

    float fpx = 0;
    float fpy = 0;
    float[] stopPoints = new float[] { 400, 360, 320, 280, 240, 200, 160, 120, 80, 40 };
    bool xFound = false;
    bool yFound = false;

    for (int i = 0; i < stopPoints.Length; i++)
        if (!xFound)
            if (data.CurrentPixel.X > stopPoints[i])
                fpx = stopPoints[i] + data.CurrentPixel.X;
                xFound = true;
                fpx = data.CurrentPixel.X;

        if (!yFound)
            if (data.CurrentPixel.Y > stopPoints[i])
                fpy = stopPoints[i] + data.CurrentPixel.Y;
                yFound = true;
                fpy = data.CurrentPixel.Y;

        if (xFound && yFound) break;

    data.FromPixel = new PointF(fpx, fpy);

    return true;
UserTransform Example (Visual Basic)
Private  Sub menuUserTransform_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Load a 24-bit image.
    Dim image As AtalaImage = New AtalaImage("D:\Test Images\1.jpg") 

    ' Apply the our own transform.
    Dim cmd As UserTransform = New UserTransform(New UserTransformCallback(UserCallback)) 
    Dim result As AtalaImage = cmd.Apply(image).Image

    ' Display the result in a WorkspaceViewer.
    Me.viewer.Image = result
End Sub

Private Function UserCallback(ByVal Data As UserTransformData) As Boolean
    ' This will take small blocks from the image and rearrange them.

    Dim fpx As Single =  0 
    Dim fpy As Single =  0 
    Dim stopPoints() As Single = New Single() {400, 360, 320, 280, 240, 200, 160, 120, 80, 40}

    Dim xFound As Boolean =  False 
    Dim yFound As Boolean =  False 

    Dim i As Integer
    For  i = 0 To stopPoints.Length- 1 Step i + 1
        If Not xFound Then
            If Data.CurrentPixel.X > stopPoints(i) Then
                fpx = stopPoints(i) + Data.CurrentPixel.X
                xFound = True
                fpx = Data.CurrentPixel.X
            End If
        End If

        If Not yFound Then
            If Data.CurrentPixel.Y > stopPoints(i) Then
                fpy = stopPoints(i) + Data.CurrentPixel.Y
                yFound = True
                fpy = Data.CurrentPixel.Y
            End If
        End If

        If xFound And yFound Then
             Exit For
        End If

    Data.FromPixel = New PointF(fpx, fpy)

    Return True
End Function
See Also