Devesprit.ImageProcessor & Devesprit.ImageServer
Extending Image Processors

Devesprit.ImageProcessor is built with extensibility in mind. All the individual processors used within the ImageFactory methods follow an interface IGraphicsprocessor which allows developers to easily extend the library.

 

IGraphicsProcessor

All the individual image processors follow an interface IGraphicsprocessor which allows developers to extend the library.

IGraphicsProcessor.cs
Copy Code
using System.Collections.Generic;
using System.Drawing;
namespace Devesprit.ImageProcessor.Processors
{
    /// <summary>
    /// Defines properties and methods for ImageProcessor Plugins.
    /// </summary>
    public interface IGraphicsProcessor
    {
        /// <summary>
        /// Gets or sets the DynamicParameter.
        /// </summary>
        dynamic DynamicParameter { get; set; }
        /// <summary>
        /// Gets or sets any additional settings required by the processor.
        /// </summary>
        Dictionary<string, string> Settings { get; set; }
        /// <summary>
        /// Processes the image.
        /// </summary>
        /// <param name="factory">
        /// The current instance of the <see cref="T:Devesprit.ImageProcessor.ImageFactory"/> class containing
        /// the image to process.
        /// </param>
        /// <returns>
        /// The processed image from the current instance of the <see cref="T:Devesprit.ImageProcessor.ImageFactory"/> class.
        /// </returns>
        Image ProcessImage(ImageFactory factory);
    }
}

Example

AdjustGamma.cs
Copy Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using Devesprit.ImageProcessor.Internal;
using Devesprit.ImageProcessor.Plugins.AdvancedEffects.Internals;
using Devesprit.ImageProcessor.Processors;
using Devesprit.ImageServer.Processors;
namespace Devesprit.ImageProcessor.Plugins.AdvancedEffects
{
    #region Effect For ImageProcessor
    public class AdjustGamma : IGraphicsProcessor
    {
        public AdjustGamma()
        {
            Settings = new Dictionary<string, string>();
            ProvidersInit.InitSystem();
        }
        public dynamic DynamicParameter { get; set; }
        public Dictionary<string, string> Settings { get; set; }
        public Image ProcessImage(ImageFactory factory)
        {
            try
            {
                var settings = (AdjustGammaSettings)DynamicParameter;
                var image = EffectProcessor.ApplyEffectToImage(factory.Image, settings);
                if (factory.Image != image)
                {
                    factory.Image.Dispose();
                    factory.Image = image;
                }
                return image;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
    #endregion


    #region Extension Method for ImageFactory Class
    public static class AdjustGammaExtension
    {
        public static ImageFactory AdjustGamma(this ImageFactory imageFactory, AdjustGammaSettings settings)
        {
            if (imageFactory.ShouldProcess)
            {
                var effect = new AdjustGamma { DynamicParameter = settings };
                imageFactory.CurrentImageFormat.ApplyProcessor(effect.ProcessImage, imageFactory);
            }
            return imageFactory;
        }
    }
    #endregion


    #region Settings
    public sealed class AdjustGammaSettings
    {
        [Description("Set the Gamma correction value. Values range from -100 to 100.")]
        public int Gamma { get; set; }
    }
    #endregion
}