Home : Image Processing : Creating a Custom ImageCommand
Q10302 - HOWTO: Creating a Custom ImageCommand

When creating a custom ImageCommand, implementing the AbstractClass will require three overloads: PerformActualCommand, SupportedPixelFormats, and VerifyProperties. In this example we will implement a command that corrects fax resolution.  

class DefaxifyCommand:ImageCommand
{

 PerformActualCommand is where the AtalaImage is modified from source to dest and is returned. In this situation, we modify the image to remove uneven fax resolutions.

    protected override Atalasoft.Imaging.AtalaImage PerformActualCommand(Atalasoft.Imaging.AtalaImage source, Atalasoft.Imaging.AtalaImage dest, System.Drawing.Rectangle imageArea, ref ImageResults results)
    {
       
Dpi sourcedpi = source.Resolution;
       
double targetdpi = Math.Max(sourcedpi.X,sourcedpi.Y);
       
PointF Ratio = new PointF((float)(targetdpi / source.Resolution.X), (float)(targetdpi / source.Resolution.Y));
       
ResampleCommand command = new ResampleCommand(new Size((int)(Ratio.X*source.Width), (int)(Ratio.Y*source.Height)));

        results = command.Apply(source);
        dest = results.Image;

        return dest;
    }

In SuppportedPixelFormats the command must return all of the PixelFormats the command supports so that the command knows when to fail.

    public override Atalasoft.Imaging.PixelFormat[] SupportedPixelFormats
    {
        
get { return new PixelFormat[] {
           
PixelFormat.Pixel16bppGrayscale, 
           
PixelFormat.Pixel16bppGrayscaleAlpha, 
           
PixelFormat.Pixel1bppIndexed, 
           
PixelFormat.Pixel24bppBgr, 
           
PixelFormat.Pixel32bppBgr, 
           
PixelFormat.Pixel32bppBgra, 
           
PixelFormat.Pixel32bppCmyk, 
           
PixelFormat.Pixel48bppBgr, 
           
PixelFormat.Pixel4bppIndexed, 
            PixelFormat.Pixel64bppBgra, 
           
PixelFormat.Pixel8bppGrayscale, 
           
PixelFormat.Pixel8bppIndexed }; 
       
}
    }

 

In VerifyProperties Normally one would perform reason checking on the properties of the command to make sure that they are within reason. In this situation there is no checking that needs to be done.

    protected override void VerifyProperties(Atalasoft.Imaging.AtalaImage image)
    {

    }

}

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved