imageComponent.NET - image processing .NET assemblies
Image Filter Parameters

Overview

PhotoController SDK provides many image filters, which might or might not contain some property parameters. Most of them do. And most parameters are just numerical type, such as integer or double. In that case, the parameter always has an accepted range. You will like to know what the range is; more importantly, your program will like to know at the runtime, not through the documentation. Hence, you can use the ParamConfig object provided in the SDK to retrieve the property type, default value, minimum value, and maximum value.

Using ParamConfig

Here is an example to show how to read the parameters configuration by using ParamConfig object and setup the client-side application form.

   1:  // this is the water filter parameter setup form
   2:  frmWater fParam = new frmWater();
   3:  fParam.Text = "Water Parameters";
   4:   
   5:  // Firstly, initialize a filter class
   6:  IC.PhotoController.Filter.WaterFilter filter = new IC.PhotoController.Filter.WaterFilter();
   7:   
   8:  // use ParamConfig to read paramater configuration
   9:  // then specify our setup form field's range
  10:  using (IC.PhotoController.ParamConfig config = new ParamConfig())
  11:  {
  12:      string max, min, defaultValue, type;
  13:      // get the definition of filter.Level
  14:      if (config.FindParam(filter.ToString(),"Level",out type,out max,out min,out defaultValue))
  15:      {
  16:          fParam.trackLevel.Maximum = int.Parse(max);
  17:          fParam.trackLevel.Minimum = int.Parse(min);
  18:          fParam.trackLevel.Value = int.Parse(defaultValue);
  19:      }
  20:   
  21:      // get the definition of filter.Wave
  22:      if (config.FindParam(filter.ToString(), "Wave", out type, out max, out min, out defaultValue))
  23:      {
  24:          fParam.trackWave.Maximum = int.Parse(max);
  25:          fParam.trackWave.Minimum = int.Parse(min);
  26:          fParam.trackWave.Value = int.Parse(defaultValue);
  27:      }
  28:  }
  29:   
  30:  // Call filter to process the image
  31:  if (fParam.ShowDialog()==DialogResult.OK) 
  32:  {
  33:      IC.PhotoController.Controller pc = new Controller(pic.Image);
  34:      filter.Level = fParam.trackLevel.Value;
  35:      filter.Wave = fParam.trackWave.Value;
  36:      filter.Edge = (EdgeType)fParam.comboBox1.SelectedIndex;
  37:      pic.Image = pc.Filter(filter);
  38:      pc.Dispose();
  39:      setRefresh(true);
  40:  }

An Alternate Method to Load Configuration

There is an XML documentation being embedded in the PhotoController.dll. The XML is formatted as follows:

   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <filters>
   3:    <filter class="SmoothFilter">
   4:      <param name="Level" max="100" min="0" default="5" type="System.Int32">
   5:      </param>
   6:    </filter>
   7:    <filter class="HSLAdjustFilter">
   8:      <param name="Hue" max="180" min="-180" default="0" type="float" />
   9:      <param name="Saturation" max="1" min="-1" default="0" type="float" />
  10:      <param name="Lightness" max="1" min="-1" default="0" type="float" />
  11:    </filter>
  12:      ........
  13:   
  14:  </filters>

The above XML is just a piece. It's pretty straightforward. If a filter has some property parameters, it will have an entry. Each property has its entry too. The following code shows how to extract this xml from the DLL.

   1:  // initialize a new instance of PhotoController
   2:  IC.PhotoController.Controller objpc = new Controller();
   3:  System.Reflection.Assembly assem = objpc.GetType().Assembly;
   4:  XmlDocument retval = new XmlDocument();
   5:  string[] names = assem.GetManifestResourceNames();
   6:   
   7:  foreach (string name in names)
   8:  {
   9:      if (name.ToLower().EndsWith(configFile))
  10:      {
  11:           Stream stream = assem.GetManifestResourceStream(name);
  12:           retval.Load(stream);
  13:           stream.Close();
  14:           stream.Dispose();
  15:           break;
  16:      }
  17:  } // end foreach
  18:  return retval;

[Back to Top]
Comments

If you feel this page can be improved or has any mistake, please enter your valuable opinion here. Or if you cannot find the information you are after, feel free to suggest a subject too. I appreciate any voice.

Your Name:
  
Your Email Address:
  
Comments: