// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
//
//
// Encapsulates methods to change the contrast component of the image.
//
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Processors
{
using System;
using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Common.Exceptions;
using ImageProcessor.Imaging.Helpers;
///
/// Encapsulates methods to change the contrast component of the image.
///
public class Contrast : IGraphicsProcessor
{
///
/// Initializes a new instance of the class.
///
public Contrast()
{
this.Settings = new Dictionary();
}
///
/// Gets or sets DynamicParameter.
///
public dynamic DynamicParameter
{
get;
set;
}
///
/// Gets or sets any additional settings required by the processor.
///
public Dictionary Settings
{
get;
set;
}
///
/// Processes the image.
///
///
/// The current instance of the class containing
/// the image to process.
///
///
/// The processed image from the current instance of the class.
///
public Image ProcessImage(ImageFactory factory)
{
Bitmap newImage = null;
Image image = factory.Image;
try
{
int threshold = (int)this.DynamicParameter;
newImage = new Bitmap(image);
newImage = Adjustments.Contrast(newImage, threshold);
image.Dispose();
image = newImage;
}
catch (Exception ex)
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;
}
}
}