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)
{
}
}