Extending ImageProcessor
Release 1.0 - ...
You can add custom developed (in Microsoft .NET) image commands to the ImageProcessor. To do this, first write a class module that implements the IImageCommand interface. The Execute method of the IImgCommand interface accepts a parameter of type ImageContext which contains all the information need to modify an image. Below is an example of a custom image command adding a watermark to each image processed by the image processor.
C# | Copy Code |
---|---|
/// <summary> /// A custom watermark image command /// </summary> public class WatermarkCommand : ImageCommandBase { private Color foreColor = Color.White; /// <summary> /// Gets or sets the foreground color. /// </summary> /// <value>The color of the fore.</value> public Color ForeColor { get { return this.foreColor; } set { this.foreColor = value; } } /// <summary> /// Executes this image command using specified context. /// </summary> /// <param name="context">The context.</param> public override void Execute(ImageContext context) { using (Graphics g = context.GetGraphics()) { string text = string.Format("Width: {0}\r\nHeight: {1}\r\nInput Type: {2}\r\nOutput Type: {3}\r\nCreated: {4}", context.ImageSize.Width, context.ImageSize.Height, context.RequestContentType, context.ResponseContentType, DateTime.Now); Font font = new Font("Verdana", 8, FontStyle.Bold); g.DrawString(text, font, Brushes.Black, 6, 6); g.DrawString(text, font, new SolidBrush(this.foreColor), 5, 5); } } } |
XML | Copy Code |
---|---|
<!-- custom watermark command --> <add type="Smartsite.ImageProcessor.TestApp.WatermarkCommand, Smartsite.ImageProcessor.TestApp" enabled="false"> <parameters> <add name="forecolor" shortcut="wfc"/> </parameters> </add> |